Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to compare combobox selected item with textbox value
Posted
Comments
DamithSL 16-Jun-14 4:34am    
what have you tried?

I would think what are you trying to compare? the combobox selected value or combobox selected text?

if comparing the text try this:

VB
if combobox1.selecteditem.text = txtname.text then

else

end if


if comparing the value try this:
VB
if combobox1.selectedvalue = txtname.text then

else

end if
 
Share this answer
 
VB
If Not String.IsNullOrWhiteSpace(ComboBox1.Text) And Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
            If ComboBox.Text = TextBox.Text Then
                MsgBox("Match")
            Else
                MsgBox("Not Match")
            End If
End If
 
Share this answer
 
Comments
tanugarg 16-Jun-14 5:17am    
IsNullOrWhiteSpace is not a member of string
J{0}Y 16-Feb-15 6:29am    
you means IsNullOrWhiteSpace does not work on comboBox
try like this:-

C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
       {

           if (comboBox1.SelectedItem.ToString() == txtName.Text)
           {
               //do something here
           }
           else
           {
               //do something here
           }
       }
 
Share this answer
 
Comments
tanugarg 16-Jun-14 6:00am    
this is not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900