VB.NET Combo Box: How to show two row


How can I show two row on my combo box in VB.NET? Access forms does a good job with it but I don't know how to do it on VB.NET?

Any Help??
Who is Participating?
chaniewskimConnect With a Mentor Commented:
the first thing (to show them in tow columns so that I have enough space between them) is problematic, because that DropDownList control simply doesn't work that way. You could concatenate strings like I shown you in the above SELECT sample and use few spaces to provide necessary gap, but it is difficult to do this so all the values are idented the same.

If you don't need to display an Employee ID on the list, but only want to assign it, then you can do it very simple:

- assign EmpName to DataTextField of your DropDownList control, and
- assign EmpID to DataValueField of that control.

Then bind DropDownList control to DataReader object using it's DataSource attribute.

Do you know how to bind it this way? Or do you need more details?
I'm going to bed now, probably I will answer you tomorow. It is 00.33 in Poland now :)
What exactly do you want to achieve? Could you give some example?
nibirkhanAuthor Commented:
on my table has two fields,

I want to show both of them EmpID and EmpName, but my bound column will be EmpID,

got it?
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Yeah, got it.

You could do this on SQL Server side, by returning a concatenation of those columns and then using resulting column as DataTextField, or,
if you're using a typed dataset, you can make a custom calculated column configuring it in dataset schema. But I think that first solution would be better and easier.
nibirkhanAuthor Commented:
could you please tell me detials or code??
When you're returning data from database for filling that combobox, simply do:

SELECT ...., EmpID + ' ' + EmpName AS EmpLabel, .... FROM MyTable....

then simply use EmpLabel for DataTextField of combobox, the same like you were doing with EmpID alone.

Why would you want to do that anyway? Looking at those field names it seems that you'd like to have EmpName bound to DataTextField and EmpId to DataValueField - or am I wrong?
nibirkhanAuthor Commented:
you are right.....thats what i want to do basically..

Ok, so that is straightforward? Or isn't it? If not, could you explain your problem again in more details?
nibirkhanAuthor Commented:
well, I understand what you are saying, you are saying to bring them in to one column but I need to show them in tow columns so that I have enough space between them...also one of them will be bound column,


If I can do this: My combo box will show Employee Name but it will assign the relative value of Employee ID on the table.... any help for this??
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.

All Courses

From novice to tech pro — start learning today.