• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

VB.NET Combo Box: How to show two row

Hi,

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??
0
nibirkhan
Asked:
nibirkhan
  • 5
  • 4
1 Solution
 
chaniewskimCommented:
What exactly do you want to achieve? Could you give some example?
0
 
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?
0
 
chaniewskimCommented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
nibirkhanAuthor Commented:
could you please tell me detials or code??
0
 
chaniewskimCommented:
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?
0
 
nibirkhanAuthor Commented:
you are right.....thats what i want to do basically..

0
 
chaniewskimCommented:
Ok, so that is straightforward? Or isn't it? If not, could you explain your problem again in more details?
0
 
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,

or,

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??
0
 
chaniewskimCommented:
OK,
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 :)
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.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now