?
Solved

Using Multiple columns in a ComboBox DisplayMember property

Posted on 2005-04-29
4
Medium Priority
?
8,387 Views
Last Modified: 2008-03-03
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
0
Comment
Question by:ethnarch
  • 2
4 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13894029
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13894067
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
 
LVL 14

Accepted Solution

by:
amyhxu earned 500 total points
ID: 13899559
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
 
LVL 2

Author Comment

by:ethnarch
ID: 13906351
thanks amyhxu that was nice and simple
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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

862 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