[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

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

0
MrDavidThorn
Asked:
MrDavidThorn
  • 3
  • 3
  • 3
  • +1
2 Solutions
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
50calCommented:
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
 
Pratima PharandeCommented:
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
 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now