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
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. DataGridViewComboBoxColumn - Multiple columns as .DisplayMember?

DataGridViewComboBoxColumn - Multiple columns as .DisplayMember?

Scheduled Pinned Locked Moved .NET (Core and Framework)
tutorialquestion
3 Posts 3 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.
  • W Offline
    W Offline
    webbooker
    wrote on last edited by
    #1

    Hi All, Easiest to explain if I show an example: I have a DataGridView which has a column that is a combo box. I have a dataset as the source, it has two columns: FirstName and LastName. I want the combo box to display "LastName, FirstName", ie, I want the display member to be a combination of two columns. Is this possible? Or will I have to add a new column to my dataset "FullName" which will be the two added together? Cheers, Brad

    L S 2 Replies Last reply
    0
    • W webbooker

      Hi All, Easiest to explain if I show an example: I have a DataGridView which has a column that is a combo box. I have a dataset as the source, it has two columns: FirstName and LastName. I want the combo box to display "LastName, FirstName", ie, I want the display member to be a combination of two columns. Is this possible? Or will I have to add a new column to my dataset "FullName" which will be the two added together? Cheers, Brad

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      webbooker wrote:

      I have a dataset as the source, it has two columns: FirstName and LastName.

      Assuming that you're using Sql, how about concatenating the fields there?

      SELECT [Field1] + [Field2] FROM ..

      I are Troll :suss:

      1 Reply Last reply
      0
      • W webbooker

        Hi All, Easiest to explain if I show an example: I have a DataGridView which has a column that is a combo box. I have a dataset as the source, it has two columns: FirstName and LastName. I want the combo box to display "LastName, FirstName", ie, I want the display member to be a combination of two columns. Is this possible? Or will I have to add a new column to my dataset "FullName" which will be the two added together? Cheers, Brad

        S Offline
        S Offline
        Scubapro
        wrote on last edited by
        #3

        The combobox only handles a single column of displayed data. It has a displaymember and a valuemember property for binding to the datasource. But if you must display multicolumn in a combobox then you can concatenante your column values, like Eddy's shown in SQL. In VB this works like:

        Dim FnLn As String
        Dim drRow As DataRow
        For Each drRow In DataSet.Rows 'or DataSet.Tables("Table1").Rows
        FnLn = drRow("Lastname") & " , " & drRow("Firstname")
        cb1.Items.Add(FnLn)
        Next

        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