Skip to content

Having trouble refreshing the display of a NumericUpDown control

Tim Reiter

Asked Mar 13, 2008, 4:24 PM EDT3 answers
Share
LinkedInX
Hi All,

I'm having a problem with a NumericUpDown control.  If the user highlights the number and hits the backspace key the number is, of course, erased.  If the user then goes to another control in the dialog box, the number is still not displayed in the NumericUpDown.  The value is still there - if the user hits the up or down arrows the number is incremented or decremented and is displayed correctly.

I tried to fix this by declaring a Leave event handler that does something to redraw or otherwise update the NumericUpDown display whenever it looses focus.  I first tried using the Refresh() method, but that did nothing.  I then tried calling Hide() followed immediately by Show(), and that also did't fix the problem.

Anyone know what I could do to make this work right?

Thanks!

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    (yes, replying to my own post...)

    OK, I found that calling UpButton() and then DownButton() seems to work.  Does anyone know of a more elegant, less cludgy solution?

    Thanks again!
    0
  • 0
    Hi, I got the same problem too, and the solution I've applied is copying .Value into .Text on the LostFocus() event:

    Private Sub MyNumericUpDown_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyNumericUpDown.LostFocus
      MyNumericUpDown.Text = MyNumericUpDown.Value
    End Sub


    So, when the control lost his focus, we always ensure that the .Text have the same value as .Value.

    Scherzo
    0