Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cannot show multiple values for combobox DisplayMember?

Cannot show multiple values for combobox DisplayMember?

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rashar
    wrote on last edited by
    #1

    Hello, I'm trying to populate my ID and Dealername in my combobox, but when I try the below scripts, I'm only seeing the ID at runtime... How can I show both the ID and DealerName in my combobox? Me.cboSelectDealer.DataSource = ReportDS.Tables("tblCall_Reports") Me.cboSelectDealer.DisplayMember = "UID" & "-" & " DealerName" Me.cboSelectDealer.ValueMember = "UID" Me.cboSelectDealer.DataSource = ReportDS.Tables("tblCall_Reports") Me.cboSelectDealer.DisplayMember = "UID" + "-" + " DealerName" Me.cboSelectDealer.ValueMember = "UID" Thanks in advance.

    C 1 Reply Last reply
    0
    • R Rashar

      Hello, I'm trying to populate my ID and Dealername in my combobox, but when I try the below scripts, I'm only seeing the ID at runtime... How can I show both the ID and DealerName in my combobox? Me.cboSelectDealer.DataSource = ReportDS.Tables("tblCall_Reports") Me.cboSelectDealer.DisplayMember = "UID" & "-" & " DealerName" Me.cboSelectDealer.ValueMember = "UID" Me.cboSelectDealer.DataSource = ReportDS.Tables("tblCall_Reports") Me.cboSelectDealer.DisplayMember = "UID" + "-" + " DealerName" Me.cboSelectDealer.ValueMember = "UID" Thanks in advance.

      C Offline
      C Offline
      Coding123456
      wrote on last edited by
      #2

      I realise this is an old post but it might help someone else out. I needed to do a similar thing but I didn't want to concatinate fields in the sql used to fill the datatable as it was contained in an existing stored procedure. So I filled the datatable with the records I wanted then basically added another column in the datatable which was my concatinated display value. I then used this new column as the DisplayMember. assuming we have a datatable which is populated with "AccountCode" and corresponding "AccountName" eg "ABC" , "Freds workshop" "XYZ" , "Bills Lighting"

      'Add a new calculated column to the datatable
      Dim DataCol As DataColumn = New DataColumn("Display")
      DataCol.DataType = System.Type.GetType("System.String")
      DataCol.Expression = "AccountCode + (' - ') + AccountName"
      dt.Columns.Add(DataCol)

      'Now setup the combobox
      cmbAvailableCompanies.DataSource = dt
      cmbAvailableCompanies.DisplayMember = "Display"
      cmbAvailableCompanies.ValueMember = "AccountsCode"

      It will now display "ABC - Freds Workshop" and "XYZ - Bills Lighting" in the combobox. The only issue I have found is if I turn sorting of the combobox on the SelectedValue of the combobox gets out of sync with the Displayed value. I haven't worked this out yet but for the time being I can live with it.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups