winforms - C# Databound Windows Forms control does not retain value unless you leave the field -
i saw answer in databound windows forms control not recognize change until losing focus.
but doesn't answer question me. have exact same situation. on toolstrip_click, go through of controls , force "writevalue()", still reverts previous value before save. can suggest how can fix this? did implement incorrectly?
(see code current (non-working) solution.)
private void menustrip1_itemclicked(object sender, toolstripitemclickedeventargs e) { // make sure items have updated databindings. foreach (control c in this.controls) { foreach (binding b in c.databindings) { // help: doesn't seem working. b.writevalue(); } } }
the code simpler, considerable hack. i'd happy know if there more "proper" fix this.
private void menustrip1_itemclicked(object sender, toolstripitemclickedeventargs e) { // make sure text fields have updated forcing // lose focus except lonely little label. label44.focus(); }
the problem databound controls set update on validation.
you need set datasourceupdatemode of each of databound controls datasourceupdatemode.onpropertychanged. example, databound textbox:
this.textbox1.databindings.add(new system.windows.forms.binding("text", this.somebindingsource, "someproperty", true, system.windows.forms.datasourceupdatemode.onpropertychanged));
you can set datasource update mode in designer :
selecting control , going property window -> (databindings) -> (advanced)
-> set [data source update mode] in dropdownlist onpropertychanged.
cheers
Comments
Post a Comment