Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to bind multiple columns from a DataTable to a Combobox

Posted on 2008-11-10
12
Medium Priority
?
511 Views
Last Modified: 2012-05-05
Okay guys, all the comboboxes I've done to this point have had one column from the datatable as the ValueMember and the DisplayMember.

I'm now working on a projectt where I need to display multiple columns from the DataTable in the combobox dropdown list.

I'm thinking my Value Member will still be my primary key from the table to follow their keystrokes if they begin to type in the combobox and my DisplayMember would be column1, column2, column3, but I've having issues getting this to work.

sql = "select Job, Customer_PO, Part_Number from Job"

da.SelectCommand = New Odbc.OdbcCommand(sql,dc)
da.Fill(tblJob)

cboJobData.DataSource = tblJob
cboJob.ValueMember = ??
dboJob.DisplayMember = ??
0
Comment
Question by:JMO9966
  • 5
  • 4
  • 3
12 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 22927375
Hi JMO9966,


You can use this (see snippet), but you can only show one column with this regular combobox.
cboJob.ValueMember = "Customer_PO"
dboJob.DisplayMember = "Job"
cboJobData.DataSource = tblJob

Open in new window

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22927380
Correction:

You have to choose the value that you will display and the value that you will store.
cboJob.ValueMember = "Customer_PO"
dboJob.DisplayMember = "Job"
cboJobData.DataSource = "Customer_PO"

Open in new window

0
 
LVL 48

Accepted Solution

by:
jpaulino earned 400 total points
ID: 22927381
Ok, last attempt :-)
cboJob.ValueMember = "Customer_PO"
dboJob.DisplayMember = "Job"
cboJobData.DataSource = tblJob

Open in new window

0
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.

 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 600 total points
ID: 22927431
0
 

Author Comment

by:JMO9966
ID: 22927572
Am I being clear, that I want to show multiple columns in the drop-down list and then also control what column follows the user keystrokes??

I'll take a look at that link now.

Thanks,
JMO9966
0
 

Author Comment

by:JMO9966
ID: 22927895
Thanks Emoreau,

I created this Windows Control Library  as the article outlines and then Built the solution.

I then open my Windows App project and then under Common Controls in my Toolbox, I do a right mouse click and choose items and browse.

I browse to the Bin\Release folder of my Control Library project and select the .dll file.

I get this error when I click Open.

"There are no components in Multi_Column_ComboBox.dll that can be placed in the Toolbox"

??

Thanks,
JMO9966

0
 

Author Comment

by:JMO9966
ID: 22927923
Forgot to add my Component Class MultiColCombo to this Control Library project, I can now add it.

I couldn't add the Inherits System.Windows.Forms.ComboBox to this class because it errored about base class having this or something so I remarked that.
0
 

Author Comment

by:JMO9966
ID: 22928018
Thanks!  I'm getting close.

In my class for the control this line fails:

Inherits System.Windows.Forms.ComboBox

"Base class 'System.Windows.Forms.ComboBox' specified for class 'MultiColCombo' cannot be different from the base class 'System.ComponentModel.Component' of one of its other partial types."

0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 400 total points
ID: 22928715
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 600 total points
ID: 22929054
>>I couldn't add the Inherits System.Windows.Forms.ComboBox

are you doing a web application? the code provided is for a Windows application. Also try to download and test the downloadable demo that goes with the article.
0
 

Author Comment

by:JMO9966
ID: 22935634
Thanks Emoreau,

This is a Windows Application and I did download the sample App and loaded that, but still having issues in my app.

JMO9966
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 600 total points
ID: 22935889
is the demo app working? what is the exact error message you have? do you have all your "Imports"?
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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

564 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