CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Focus question

  1. #1
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Focus question

    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?

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Focus question

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured