2

I want to set minValue and maxValue of text boxes to define a range of acceptable values for validation purposes.

In VB 6 this is straight forward and can be done under text box properties, however in visual studio vb .net 2010 this is not the case or it may be the case that i am missing something.

Thanks, Ayub

3
  • Are we talking about numbers here? Or Dates? Or ...? Commented Aug 29, 2011 at 11:24
  • Then go with LarsTech's answer Commented Aug 29, 2011 at 11:30
  • VB6's textbox has no such properties. Nor does it make sense, a textbox edits text, not numbers. Commented Aug 29, 2011 at 11:43

4 Answers 4

3

In WinForms, there is a NumericUpDown control that you can use, and it has properties for Minimum and Maximum.

Sign up to request clarification or add additional context in comments.

5 Comments

Yes it works, but it would be great if i can set range of a text box without writing IF - ELSE i.e setting it under its properties :)
@Ayub That's what the Minimum and Maximum properies are for-- just set your values in there.
NumericUpDown Works great, but it has a Default Value (a number)... the problem is that data entry people may skip few numUpDown fields as they are already filled with a default value
@Ayub That's a different question than the one you posted. You can always have a range of -1 to 50 and if it's -1, bug the user to enter a different number.
right! i had the same idea '-1' :D, normally the ranges are from 0 - 9, -1 could be used as a default empty value
0

What you need is a numeric text box control with according properties. AFAIK MS does not provide one, but there are free solutions available like this one:

http://www.codeproject.com/KB/edit/HDNumericTextBox.aspx

Comments

0

make a customized textbox - thats checks the ascii of the entered value and - restrict the value to numeric., like - try with KeyDown or keypress events of text box and catch the keycode or event sender..

1 Comment

i am trying not to handle it with code, just like in VB6 there is option for Min/Max value for each text box
0

Try using the RangeValidator.

1 Comment

Please explain your answer why we should use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.