|
-
Jan 14th, 2013, 02:18 AM
#1
Thread Starter
Member
how do i validate textbox input against ddl value range
i have a drop down list with weight range values i.e 1-50 or 51-70 and so forth and i have a textbox that the user enters a value for the weight according to the weight range. i want the user to only enter a value within this range and how do i validate for this
-
Jan 14th, 2013, 04:32 AM
#2
Re: how do i validate textbox input against ddl value range
So, this is a web application and you have a DropDownList control or is it a Windows app and it's actually a ComboBox? If you use the actual names for things then it avoids confusion. Also, questions on web applications are generally better posted in the ASP.NET forum.
-
Jan 14th, 2013, 04:37 AM
#3
Thread Starter
Member
Re: how do i validate textbox input against ddl value range
hie thanks for the response. Its a windows form app and its a normal combobox
 Originally Posted by jmcilhinney
So, this is a web application and you have a DropDownList control or is it a Windows app and it's actually a ComboBox? If you use the actual names for things then it avoids confusion. Also, questions on web applications are generally better posted in the ASP.NET forum.
-
Jan 14th, 2013, 04:45 AM
#4
Re: how do i validate textbox input against ddl value range
There's no such thing as a normal ddl in Windows Forms. The control is called ComboBox so please use the name ComboBox when you refer to it so that we don't have to waste our time trying to clarify. As I said, if you use the proper name for everything then there's no confusion and we can provide you with the help you want without wasting our time or yours.
Anyway, there are various ways that this could be done. The easiest in your case might be to use a couple of arrays:
Code:
Private minima As Integer() = {1, 51}
Private maxima As Integer() = {50, 70}
You can then use the SelectedIndex of the ComboBox as an index into both the arrays to get the minimum and maximum values allowed, e.g.
Code:
Dim index As Integer = ComboBox1.SelectedIndex
Dim minimum As Integer = minima(index)
Dim maximum As Integer = maxima(index)
If theNumber < minimum OrElse theNumber > maximum Then
MessageBox.Show(String.Format("Please enter a value in the range {0} to {1} inclusive.", minimum, maximum))
End If
-
Jan 14th, 2013, 04:57 AM
#5
Thread Starter
Member
Re: how do i validate textbox input against ddl value range
thanks for the idea...but in my case i dont know what weight ranges the user will input so i cannot use the arrays. is there any other way
-
Jan 14th, 2013, 05:03 AM
#6
Re: how do i validate textbox input against ddl value range
I must have missed the part where you told us that the user was entering those ranges. You can still use the same principle though. You can use List(Of Integer) instead of Integer() and then you can add new ranges at run time.
-
Jan 14th, 2013, 05:22 AM
#7
Thread Starter
Member
Re: how do i validate textbox input against ddl value range
it has given me an error object reference not set to an instance of an object on line
dim minimum as integer = minima(index)
i have used the textbox validating control
-
Jan 14th, 2013, 06:11 AM
#8
Re: how do i validate textbox input against ddl value range
There is no TextBox validating control. Do you mean the Validating event of the TextBox control?
What was the value of 'index" when the error occurred? If there was not item selected then it would have been -1, so you obviously need to code for that special case specifically. If it was any other value then the error occurred because you did it wrong, but we can't tell you what you did wrong because we can't see what you did. If the number of items in the arrays/collections is the same as in the ComboBox then it will work, except for the special case of no item selected, which would need to be coded for specifically.
Tags for this Thread
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
|