By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Check for existing value in Combobox list

P: n/a

I have a textbox and a combobox on a toolstrip. The user enters either an
ID in the textbox or selects a name from the combobox. When the user
selects a name from the combobox the textbox is filled in automatically by
setting its .Text property equal to the .SelectedValue of the combobox.
When the user enters an ID in the textbox the combobox's .SelectedValue is
set to the .Text value in the ID textbox. All works fine but it is
possible to enter a value in the ID textbox that does not exist in the
combobox. So I have written a procedure to check for the existence of the
value in the combobox prior to setting the value. The procedure is shown
below. My question is: Is it possible to do this without iterating
through the values, i.e. is there a single line of code using something
like .Contains that enables me to do the same thing ?
Private Sub txtCustIDEnter_Leave(ByVal sender As System.Object, ByVale
As System.EventArgs) Handles txtCustIDEnter.Leave

Dim strCustID As String = Me.txtCustIDEnter.Text.Trim.ToUpper

If strCustID.Length <0 Then
For Each drv As DataRowView In Me.cboCustNameSelect.ComboBox.Items
If drv.Row.Item(0).ToString.ToUpper = strCustID Then
Me.cboCustNameSelect.ComboBox.SelectedValue = strCustID
Exit For
End If
Next
End If

End Sub



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 9 jul, 15:37, DesCF <d...@aol.comwrote:
I have a textbox and a combobox on a toolstrip. The user enters either an
ID in the textbox or selects a name from the combobox. When the user
selects a name from the combobox the textbox is filled in automatically by
setting its .Text property equal to the .SelectedValue of the combobox.
When the user enters an ID in the textbox the combobox's .SelectedValue is
set to the .Text value in the ID textbox. All works fine but it is
possible to enter a value in the ID textbox that does not exist in the
combobox. So I have written a procedure to check for the existence of the
value in the combobox prior to setting the value. The procedure is shown
below. My question is: Is it possible to do this without iterating
through the values, i.e. is there a single line of code using something
like .Contains that enables me to do the same thing ?

Private Sub txtCustIDEnter_Leave(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtCustIDEnter.Leave

Dim strCustID As String = Me.txtCustIDEnter.Text.Trim.ToUpper

If strCustID.Length <0 Then
For Each drv As DataRowView In Me.cboCustNameSelect.ComboBox.Items
If drv.Row.Item(0).ToString.ToUpper = strCustID Then
Me.cboCustNameSelect.ComboBox.SelectedValue = strCustID
Exit For
End If
Next
End If

End Sub

--
Using Opera's revolutionary e-mail client:http://www.opera.com/mail/
Hi...
How about to use a LIKE query: "SELECT Id FROM Table1 WHERE Id LIKE '"
+ TextBox1.Text + "%'"

Jul 10 '07 #2

P: n/a
I had it mind that I didn't want to open a connection back to the server
just to check for the existence of a Customer ID when the combobox is
already populated by a valid list of Customer ID's which I could check
against. What has occurred to me is perhaps something I don't quite
understand because of my 'newness' to this, i.e. if I have a dataset with
a datatable in it that contains a list of customers how do I check against
the table in the dataset and not the table back on the server ?

Des
On Tue, 10 Jul 2007 23:39:28 +0100, diAb0Lo <ga********@gmail.comwrote:
On 9 jul, 15:37, DesCF <d...@aol.comwrote:
>I have a textbox and a combobox on a toolstrip. The user enters either
an
ID in the textbox or selects a name from the combobox. When the user
selects a name from the combobox the textbox is filled in automatically
by
setting its .Text property equal to the .SelectedValue of the combobox.
When the user enters an ID in the textbox the combobox's .SelectedValue
is
set to the .Text value in the ID textbox. All works fine but it is
possible to enter a value in the ID textbox that does not exist in the
combobox. So I have written a procedure to check for the existence of
the
value in the combobox prior to setting the value. The procedure is
shown
below. My question is: Is it possible to do this without iterating
through the values, i.e. is there a single line of code using something
like .Contains that enables me to do the same thing ?

Private Sub txtCustIDEnter_Leave(ByVal sender As System.Object,
ByVal e
As System.EventArgs) Handles txtCustIDEnter.Leave

Dim strCustID As String = Me.txtCustIDEnter.Text.Trim.ToUpper

If strCustID.Length <0 Then
For Each drv As DataRowView In
Me.cboCustNameSelect.ComboBox.Items
If drv.Row.Item(0).ToString.ToUpper = strCustID Then
Me.cboCustNameSelect.ComboBox.SelectedValue = strCustID
Exit For
End If
Next
End If

End Sub

--

Hi...
How about to use a LIKE query: "SELECT Id FROM Table1 WHERE Id LIKE '"
+ TextBox1.Text + "%'"


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.