Solved

Control to display multi-column selection

Posted on 2004-09-14
7
513 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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