D
DesCF
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
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