Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Databound Windows Forms control does not recognize change until losing focus

I use data binding to display values in text boxes in a C# Windows Forms client. When the user clicks Save, I persist my changes to the database. However, the new value in the active editor is ignored (the previous value is saved). If I tab out of the active editor, and then Save, the new value is persisted, as expected.

Is there a way to force the active control to accept its value before persisting?

like image 908
Pato Avatar asked Jun 29 '09 19:06

Pato


1 Answers

If you can get the Binding instance that corresponds to the input (the TextBox), you can call the WriteValue method to force the value from the control to the object it is bound to.

Also, you can call the EndCurrentEdit method on the BindingManagerBase class (usually a CurrencyManager class instance) to finish the edit, but that requires implementation of the ICancelAddNew or IEditableObject interface on the object that is bound to (and wouldn't require you to fish for the binding).

like image 82
casperOne Avatar answered Sep 29 '22 08:09

casperOne