Note, I screwed up and asked how to get DisplayMember text, I meant to put ValueMember...

I have a combo box I'm populating from a datatable. It has two columns, one for display and one for value. I can find the index of the associated item in the combobox list using the FindString method, but how do I retrieve the value member string from the return of this?

Dim selectedText as String = ""
        Dim indexitem As Integer = ComboBox1.FindString(ComboBox1.Text)
        ComboBox1.SelectedItem = indexitem 'If I type the value in the combo box, selected item is nothing
        selectedText = ComboBox1.SelectedValue.ToString 'Throws Null Reference Exception if user typed in value into combobox rather than selecting
        Debug.Print("Found {0} at index {1}, which turns out to be code: {2}", ComboBox.Text, indexitem.ToString, selectedText)

I do apologize... I answered my own question. I noticed that I was trying to set the "SelectedItem". I should've been trying to set the "SelectedIndex".

If you happen to know of a more elegant solution, please feel free to reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.