Using Multiple columns in a ComboBox DisplayMember property

I have a dataset i am binding to a ComboBox and i want the drop down combobox to display 2 columns from a table.
For Instance if i have a vendor_No column and a Vendor_Name column i want the drop down list to show
 
1 Vendor1
2 Vendor2
3 Vendor3

So far i can only seem to figure out how to have only one column displayed i tried doing something simple like this

ComboBox2.DisplayMember = "Vendor_No + '  ' + Vendor_Name"

No luck with anything along those lines, there must be a way though. Any help would be greatly appreciated
LVL 2
ethnarchAsked:
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.

 
RonaldBiemansCommented:
0
 
RonaldBiemansCommented:
or just use a class like

Public Class Vendor

   Private m_Vendor_No As integer
   Public m_Vendor_Name As String

   Public Sub New(ByVal vendorid As Integer, ByVal vendorname As String)
       m_verdorname= vendorname
       m_vendorid = vendorid
   End Sub

   Public Overrides Function ToString() As String
       Return m_vendorid  & " " & m_vendorname
   End Function
End Class

'And my combo box population is:
Do While dr.Read()
   combobox1.Items.Add(New Vendor(dr.Item("Vendor_ID"), dr.Item("Vendor_Name")))
Loop
0
 
amyhxuCommented:
If you still want to use "ComboBox2.DisplayMember = ...", you can work something in the SQL part.
The query to generate the dataset can be something like this:
  SELECT Vendor_No, Vendor_Name, Cast(Vendor_No As varchar(20)) + ' ' + Vendor_Name As Vendor_No_And_Name From myTable ...

Then in your code for populating the combobox after the dataset is filled:
  ComboBox2.DataSource = myDataSet.Tables("myTable")
  ComboBox2.DisplayMember = "Vendor_No_And_Name"
  ComboBox2.ValueMember = "Vendor_No"
0

Experts Exchange Solution brought to you by ConnectWise

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
 
ethnarchAuthor Commented:
thanks amyhxu that was nice and simple
0
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.