Control to display multi-column selection
Posted on 2004-09-14
I need to perform a lookup on a SQL 2000 database, and utilize the results in a control for user selection. The data will be used as a validation control to ensure the only Employees that reside in our Employee database will have accounts created on the network. I understand enough to get me as far as the code below, but need additional help.
'Generate SQL connection with string
Dim CPcon As SqlConnection = New SqlConnection("MYDATASOURCE")
'Create SQL command with select statement
Dim cmd As SqlCommand = New SqlCommand("SELECT EMPL_ID,FIRST_NAME,LAST_NAME FROM EMPL", CPcon)
'Set timeout to 30 seconds on connection
cmd.CommandTimeout = 30
'Create a DataAdapter
Dim DA As SqlDataAdapter = New SqlDataAdapter
'Set command for Data Adapter to execute
DA.SelectCommand = cmd
Dim ds As DataSet = New DataSet
'Fill Dataset from Data Adapter from the Employee Table
'Set datasource of combobox to Employee table in Dataset
ComboBox1.DataSource = ds.Tables("EMPL")
'Set the display member of Combo box
ComboBox1.DisplayMember = "LAST_NAME"
ComboBox1.ValueMember = "EMPL_ID"
Catch ex As Exception
This code works fine at returning a single value as the datasource of the combobox, but I really need to have the employee ID, First Name, and Last Name all in the selection and return only the Employee ID when SelectedIndexChanged event fires. I have seen a few places where the drop down was changed to show a datagrid selection, but I am not technically adept enough to understand how to implement that. I have also heard and utilized owener drawn controls, but the down side is the way that the data lines up. If there is another control that would be better sutied to displaying a list of this data in a selectable format, I am willing to use it instead.