1
votes

I have a NumericUpDown control that is bound to an int property on a business object which implements INotifyPropertyChanged. The Data Source Update Mode for the NumericUpDown control is set to OnPropertyChanged and the ReadOnly property of the control is set to false. This works as expected with one exception: if I enter a value into the textbox portion of the NumericUpDown control, the value of the property that the control is bound to doesn't get updated until the control loses focus.

I have a ToolStrip with several buttons on my form. Clicking on these buttons won't cause the NumericUpDown control to lose focus so before I do anything with my business object via one of these button clicks, I call toolStrip.Focus() to make sure that the value in the textbox portion of the NumericUpDown control has been pushed back to the business object. This seems to work for me but I'd like to know if this is the expected behavior of the NumericUpDown control in this scenario and, if so, how other people work around this situation? Thanks for your feedback!

2

2 Answers

4
votes

I've had a similar problem where I used the WriteValue function

numericUpDown.DataBindings["Value"].WriteValue();

This worked when it wasn't writing the value until the control lost focus.

2
votes

numericUpDown.DataBindings["Value"].ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;