Numeric UpDownControl Issues

Learner

Member
Joined
Jul 4, 2005
Messages
5
Programming Experience
Beginner
Hi all,

I am working on windows form that contains NumericUpDownControls.

I need to solve the following issues with the controls:

1-Is there any way to restrict control value length if user manually entered the value in control? (Just like TextBox control MaxLength property). (I set the Min and Max values one and ten respectively but the control allows entering thousands of digits in it).​

2 – Is there any way to validate control values if user manually entered zeros before digit?

3- Also how to restrict control not to allow empty value?

Thanks in advance.

Asif
 
The issue is with what is displayed in the NUD rather than what its Value property contains. The contents of the NUD is not validated until it loses focus, but the Text is not updated to match the Value properly. If you just add this code:
VB.NET:
    Private Sub NumericUpDown1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles NumericUpDown1.Leave
        Me.NumericUpDown1.Value = Me.NumericUpDown1.Value
    End Sub
You'll find that it will be updated properly. The user will still be allowed to enter values greater than the maximum and less than the minimum, but they will be changed to the limiting values when the control loses focus.
 
Back
Top