|
-
Apr 4th, 2007, 04:20 AM
#1
Thread Starter
Addicted Member
[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.
Last edited by CodeKiller; Apr 4th, 2007 at 07:45 AM.
---------------------------------------------------
VB 2003
SQL Server 2000
-
Apr 4th, 2007, 07:06 AM
#2
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"))
-
Apr 4th, 2007, 07:45 AM
#3
Thread Starter
Addicted Member
Re: Selecting value using combobox
Excellent, thanks very much.
Have also removed offending line.
---------------------------------------------------
VB 2003
SQL Server 2000
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|