|
-
July 19th, 2012, 10:42 AM
#1
[RESOLVED] [VB.NET-VS2010] Limit the number of digits in a NumericUpDown
I have a numericupdown with a minimum set at 0 and a maximum at 100. However, at run-time a user may input an infinite number by skipping the arrows and inputting numbers with keys. I have tried to solve this myself but my error message won't popup until the user presses the enter key.
Code:
Private Sub spnMiscQty_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles spnMiscQty.ValueChanged
If spnMiscQty.Value = 100 Then
MessageBox.Show("Pick a Quantity between 1 and 100")
Else
End If
End Sub
What I would really like to do to by-pass this issue is to limit the number (cannot enter a value greater than '100') or to disallow a cursor to be placed in the NumericUpDown (user would only be allowed to use the arrows to select a number).
Thanks in advance for any help you may provide.
-
July 19th, 2012, 10:47 AM
#2
Re: [VB.NET-VS2010] Limit the number of digits in a NumericUpDown
Why? Let the user choose, then change the query to:
If spnMiscQty.Value > 100 or spnMiscQty.Value < 0 Then ...
-
July 19th, 2012, 11:02 AM
#3
Re: [VB.NET-VS2010] Limit the number of digits in a NumericUpDown
I posted the wrong code. That code was to check if the message box was working before I found out about the Enter key initiating the msgbox. I did have spnMiscQty.Value > 100 before that.
I do not want the user to be able to choose a quantity above 100 because this program needs to be airtight. No room for error with my bosses...even user error.
Thanks for your quick reply David.
-
July 20th, 2012, 01:16 AM
#4
Re: [VB.NET-VS2010] Limit the number of digits in a NumericUpDown
Instead of using valuechanged event, use the Keypress event and trap them there....
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
July 20th, 2012, 01:44 AM
#5
Re: [VB.NET-VS2010] Limit the number of digits in a NumericUpDown
Have a look at this thread, it explains why this happens :
http://www.vbdotnetforums.com/window...html#post20621
It is the default behaviour. If you want to change that, you will need to make a custom NumericUpDown ( your own ). Not sure if it will be a worthwhile effort
-
July 20th, 2012, 08:47 AM
#6
Re: [VB.NET-VS2010] Limit the number of digits in a NumericUpDown
That's very interesting. I guess I never really took the time to play around with NumericUpDowns before this week. I guess I will leave it as is.
Thanks for the article Hannes!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|