Using Multiple columns in a ComboBox DisplayMember property

Posted on 2005-04-29
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
Question by:ethnarch
    LVL 25

    Expert Comment

    LVL 25

    Expert Comment

    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")))
    LVL 14

    Accepted Solution

    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"
    LVL 2

    Author Comment

    thanks amyhxu that was nice and simple

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    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…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now