How to bind multiple columns from a DataTable to a Combobox

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 = ??
JMO9966Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
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
Jorge PaulinoIT Pro/DeveloperCommented:
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
Jorge PaulinoIT Pro/DeveloperCommented:
Ok, last attempt :-)
cboJob.ValueMember = "Customer_PO"
dboJob.DisplayMember = "Job"
cboJobData.DataSource = tblJob

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Éric MoreauSenior .Net ConsultantCommented:
0
JMO9966Author Commented:
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
JMO9966Author Commented:
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
JMO9966Author Commented:
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
JMO9966Author Commented:
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
Jorge PaulinoIT Pro/DeveloperCommented:
0
Éric MoreauSenior .Net ConsultantCommented:
>>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
JMO9966Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
is the demo app working? what is the exact error message you have? do you have all your "Imports"?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.