Finding value in Combobox

Im trying to match a value in a combo box with a value in a text box, however the below code always returns a nothing value even though there is a match between the text in the text box and a value in the combo box, the code works correctly when the value being match is in a querystring but fails when in a text box any ideas?
ListItem = ComboBox.Items.FindByValue(Left(txtValue.Text, 3))

        If ListItem Is Nothing Then
            ComboBox.SelectedIndex = 0
        Else
            ComboBox.SelectedValue = txtValue.Text        End If

Open in new window

MrDavidThornAsked:
Who is Participating?
 
Pratima PharandeConnect With a Mentor Commented:
I have tested it , its working for me

  Dim ListItem As New ListItem
        ListItem = ComboBox.Items.FindByValue(txtValue.Text)

        If ListItem Is Nothing Then
            ComboBox.SelectedIndex = 0
        Else
            ComboBox.SelectedValue = txtValue.Text
        End If

are you doing something on Page_Load
0
 
50calCommented:
Are you certain that the value contains data?
What happens if you return the SelectedText property?

50cal.
0
 
Pratima PharandeCommented:
ComboBox.SelectedValue = txtValue.Text

here also you need to select serch val;ue ? correct?

ComboBox.SelectedValue = Left(txtValue.Text, 3))

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
MrDavidThornAuthor Commented:
sorry i  put the left string function in to to try and work out why its not working, yup the values are there can not figure it out for the life of me.
0
 
sarabhaiCommented:
Debug the query-string and textbox value.
you may get the idea.
 
0
 
50calCommented:
So if you replace txtValue.Text with "MyValue" as a string the code works?

50cal.
0
 
Pratima PharandeCommented:
Trim the text and try
0
 
MrDavidThornAuthor Commented:
nope Iv tried replacing the textbox.text with the physical string and still no joy, Iv done a debug and the strings match Exactly.
0
 
50calConnect With a Mentor Commented:
I think this MSDN article does what you are trying to achieve.

http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindex.aspx#Y700
Private Sub findButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim index As Integer
    index = comboBox1.FindString(textBox2.Text)
    comboBox1.SelectedIndex = index
End Sub

Open in new window

0
 
MrDavidThornAuthor Commented:
found the problem, the combo box I have is bound to a  query that is returing 25000 records (which is a bit much for a combo box) so it seems to be a design issue.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.