?
Solved

Control to display multi-column selection

Posted on 2004-09-14
7
Medium Priority
?
515 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 14

Expert Comment

by:ptakja
ID: 12060756
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
ID: 12063663
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
ID: 12067803
Do you have code examples for the multi-column listbox? That would problably do the trick!
0
 

Author Comment

by:john_vernon
ID: 12073957
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
ID: 12327294
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 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