Solved

Control to display multi-column selection

Posted on 2004-09-14
7
510 Views
Last Modified: 2008-01-09
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
        'Exception Handling
        Try
            'Open Connection
            CPcon.Open()
            'Create Dataset
            Dim ds As DataSet = New DataSet
            'Fill Dataset from Data Adapter from the Employee Table
            DA.Fill(ds, "EMPL")
            '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
            MessageBox.Show(ex.ToString)
        Finally
            'Close connection
            CPcon.Close()
        End Try

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.
0
Comment
Question by:john_vernon
  • 3
7 Comments
 
LVL 14

Expert Comment

by:ptakja
Comment Utility
You could use a grid or a multi-column list box.

I  don't think the standard Combobox supports multiple columns.  If I remember, you would need to go with a third-party control, such as the UltraComboBox from Infragistics (http://www.infragistics.com).  The UltraComboBox control basically combines a grid with a combobox.  So you can have a combo with multiple columns, and have it return a value to your code from a visible column, or a hidden one.  It is part of the NetAdvantage suite.  Base price will run you about $500.
0
 

Author Comment

by:john_vernon
Comment Utility
For such a simple program, I would not be willing to make that type of investment.  Is there an open source alternative?
0
 

Author Comment

by:john_vernon
Comment Utility
Do you have code examples for the multi-column listbox? That would problably do the trick!
0
 

Author Comment

by:john_vernon
Comment Utility
I have temporarily solved my own problem by creating an additional field in the database to hold the content of my combo/listbox.  It was not the approach I was looking for but it gets me to my next step.  I would still be willing to give the points to anyone with a good code example.  I have read several other posts pertaining to other control sets with the ability to add multiple columns, but for these controls it did not appear that you could set a datasource.  Instead, you would have to add items in one at a time.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now