jhammer
April 21st, 2005, 02:29 AM
I have a NumericUpDown and a Button. The NumericUpDown is bounded to a DataTable column.
When the user insert the value manually (not using the up and down), and he then presses the button, the changes he made in the NumericUpDown are not applied to the DataSource.
I tried EndCurrentEdit and it didn't work.
Any suggestions?
jhammer
April 27th, 2005, 01:58 AM
Well, I finally found a solution. I inserted this part to a class which inherits from NumericUpDown:
private bool _lockEnterLeave = false;
private Decimal _beforeValue;
private void MyNumericUpDown_Leave(Object sender, EventArgs e)
{
If (Value == _beforeValue) return;
_lockEnterLeave = true;
this.UpButton();
this.DownButton();
_lockEnterLeave = false;
}
private void MyNumericUpDown_Enter(Object sender, EventArgs e)
{
If (_lockEnterLeave) return;
_beforeValue = Value;
}
The Up and Down buttons are pressed in the OnLeave method (which cause the information to temain the same), and the edit is ended.
The problem is that if the user did not change the value, then the Leave method is called also. So there is a mechanism in Enter which saves the value, and in Leave there is a compare mechanism with the saved value. (I added a lock to save problems when clicking on the Up and Down buttons.
One last thing: I hate those Microsoft guys for making me go through all this long and bumpy road. They really should have been implemented this. The NumericUpDown is really not very good.