winforms - C# Override OnValidating to support null value but breaks Data Binding -
winforms - C# Override OnValidating to support null value but breaks Data Binding -
i have customtextbox inherits textbox , overwrites onvalidating method allow empty strings. customtextbox bound property cost in domain.
public class customtextbox { protected override void onvalidating(...) { if(text=="") { text = null; return; } base.onvalidating(e); } } public class domain { public system.nullable<decimale> cost { ... } } all works except prevents users froming setting cost null. text=null; did not propogate domain object. there way reset cost null when user clears out textbox?
if using binding propagate values domain object, should set logic in parse event instead.
// add together binding var b = new binding("text", mydatasource, "boundproperty"); b.parse += onnullabletextbindingparsed; mytextbox.databindings.add(b); // sample parse handler private void onnullabletextbindingparsed(object sender, convertereventargs e) { if (e.value == string.empty) e.value = null; } c# winforms
Comments
Post a Comment