Block NumericUpDown ValueChanged event til button released

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robertybob
    New Member
    • Feb 2013
    • 116

    Block NumericUpDown ValueChanged event til button released

    Hi

    I have a NumericUpDown that triggers quite a substantial amount of calculations when its value is changed.

    Therefore it would surely be prudent to not have this firing on every increment if the user wants to use the buttons to change the value through a lot of increments by holding the button down.

    Is there a way to prevent the valuechanged event firing until they actually release the button?

    Many thanks in advance.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What event are you using? Try using the mouseup event instead.

    Comment

    • robertybob
      New Member
      • Feb 2013
      • 116

      #3
      Hi Rabbit,

      I originally had a MouseUp which works great for using the buttons but then it doesn't trigger anything if typing the value into the box instead....

      Actually, I thought the NumericUpDown didn't like the KeyUp event but seems when I check now the code isn't saying I can't use it - so maybe I can now use a KeyUp and MouseUp event.

      The issue there will be forcing the cursor to the end of the NumericUpDown entry after each KeyUp event...

      Thanks again.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Sounds like you know what you want to try. Good luck, let us know how you get along.

        Comment

        • robertybob
          New Member
          • Feb 2013
          • 116

          #5
          Ok - the decimal place in the NumericUpDown causes a few issues with the KeyUp but I've decided that if it triggers when it gets to a double-digit number input then its ok - they can deal with the 1/10s via the up/down.

          So I've separated the MouseUp event to trigger the calculations and the KeyUp events. The KeyUp event code is as follows which seems the best I can do for now but is fine.

          Code:
          Dim nudcontrol As NumericUpDown = DirectCast(sender, NumericUpDown)
          If nudcontrol.Text.Length >= 2 Then
          nudcontrol.Select(nudcontrol.Text.Length, 0)
          doCalcs()
          End If
          All the best

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            What do you mean by "best you can do". If you explained what else you want it to do, perhaps we can find a solution.

            Comment

            Working...