|
-
Jan 15th, 2009, 09:12 AM
#1
Thread Starter
Lively Member
[RESOLVED] Check text entered in combobox against the dropdownlist genereated
Hi,
I have an windows mobile application. In the windows form of it, I have a combo box.
I load the values in the combobox on frm_load event.
Now we all know what the combo box has the facility that it allows to enter text as well as chose from the dropdown.
So when they enter the text, I want to validate it against the list that is in it.
If not then msbox error.
Can you guide me with,how to validate.
My loading of the combo box is here.
Code:
Private Sub mainfrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New SqlConnection("XXXX")
Try
con.Open()
Catch ex As Exception
'MsgBox("Problem in Connection with the SQL server")
End Try
Try
' filling the combobox with distinct bin numbers
Dim cmd1 As New SqlCommand(" Select distinct Binnumber from [dbo].[bintable]", con)
Dim rd1 As SqlDataReader = cmd1.ExecuteReader()
While rd1.Read()
Barcode2.Items.Add(rd1(0).ToString)
End While
Catch ex As Exception
MsgBox("Error loading the combo box with bin numbers.")
con.Close()
End Try
Barcode1.Focus()
End Sub
-
Jan 15th, 2009, 09:23 AM
#2
Re: Check text entered in combobox against the dropdownlist genereated
Can you not just set the style to DropDownList so that they HAVE to select one from the list?
-
Jan 15th, 2009, 09:28 AM
#3
Thread Starter
Lively Member
Re: Check text entered in combobox against the dropdownlist genereated
I wish I could. If that was the case iwould have put a listbox or dropdown box, and not a combo box.
Sorry Chris, its a requirement.
-
Jan 15th, 2009, 09:37 AM
#4
Re: Check text entered in combobox against the dropdownlist genereated
OK it was just a suggestion in case you were not aware of that property.
As for validating the text against the items within the combobox, as it seems that you are just adding strings to the combobox you should just be able to do this:
vb Code:
If MyComboBox.Items.Contains(MyComboBox.Text) Then
'Valid input entered
Else
'The text isnt in the list
End If
-
Jan 15th, 2009, 09:48 AM
#5
Thread Starter
Lively Member
Re: Check text entered in combobox against the dropdownlist genereated
Thanks. it worked perfectly!
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
|