[RESOLVED] Selecting value using combobox
Hi All,
is it possible for me to select an additional value from my datatable when selecting a value in a combobox?
I have a sql query:
SELECT KeyCol, Col2, Col3 FROM TestTable
I bind the combo like so:
cboTest.DataSource = dtTest
cboTest.DisplayMember = "Col2"
cboTest.SelectedItem = "KeyCol"
cboTest.ValueMember = "KeyCol"
Now what I would like to do is get the value of "Col3" when the user fires the selectedindex_changed event.
Hope this is clear, any help appreciated.
Re: Selecting value using combobox
Firstly, that third line is not going to do anything useful.
As for your question, when the user makes a selection the SelectedItem is a DataRowView. You can get any field you want from that, e.g.
vb Code:
Dim col3Val As String = CStr(DirectCast(myComboBox.SelectedItem, DataRowView)("Col3"))
Re: Selecting value using combobox
Excellent, thanks very much.
Have also removed offending line.