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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With