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. C#
  4. Multiple values in ComboBox.DisplayMember

Multiple values in ComboBox.DisplayMember

Scheduled Pinned Locked Moved C#
collaborationhelpquestion
10 Posts 4 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.
  • B Offline
    B Offline
    beqs
    wrote on last edited by
    #1

    Hope someone can help me. I want to add two values in a combobox. It's for players of a team. Now I have done it as follow with an DataSet: cbPlayers.DataSource = dsPlayers.Tables["Players"]; cbPlayers.ValueMember = "PlayerID"; cbPlayers.DisplayMember = "FullName"; This gives a combobox filled with only playernames But I also would like to include the team name behind the playername in this combobox. Who can help me out?:confused:

    L M 3 Replies Last reply
    0
    • B beqs

      Hope someone can help me. I want to add two values in a combobox. It's for players of a team. Now I have done it as follow with an DataSet: cbPlayers.DataSource = dsPlayers.Tables["Players"]; cbPlayers.ValueMember = "PlayerID"; cbPlayers.DisplayMember = "FullName"; This gives a combobox filled with only playernames But I also would like to include the team name behind the playername in this combobox. Who can help me out?:confused:

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Create a property that returns that. Will probably be in the generated C# file from the XSD. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

      1 Reply Last reply
      0
      • B beqs

        Hope someone can help me. I want to add two values in a combobox. It's for players of a team. Now I have done it as follow with an DataSet: cbPlayers.DataSource = dsPlayers.Tables["Players"]; cbPlayers.ValueMember = "PlayerID"; cbPlayers.DisplayMember = "FullName"; This gives a combobox filled with only playernames But I also would like to include the team name behind the playername in this combobox. Who can help me out?:confused:

        M Offline
        M Offline
        Mohamad Al Husseiny
        wrote on last edited by
        #3

        If You don't find suitable solution you can create custom class that have properties that you want and load combobox by code instead of data binding this way you can control what text will appear in each combobox item MCAD

        A 1 Reply Last reply
        0
        • M Mohamad Al Husseiny

          If You don't find suitable solution you can create custom class that have properties that you want and load combobox by code instead of data binding this way you can control what text will appear in each combobox item MCAD

          A Offline
          A Offline
          Alomgir Miah
          wrote on last edited by
          #4

          Hi Mohamad, Is there a way to do it through DataView. I could not find a way to merge columns togather. RowFilter is the only thing you can do. Live Life King Size Alomgir Miah

          M 1 Reply Last reply
          0
          • A Alomgir Miah

            Hi Mohamad, Is there a way to do it through DataView. I could not find a way to merge columns togather. RowFilter is the only thing you can do. Live Life King Size Alomgir Miah

            M Offline
            M Offline
            Mohamad Al Husseiny
            wrote on last edited by
            #5

            Hi Alomgir Sorry i don't understand what you mean can you explain it more? What i want to say that he can create custom class which contain properties like PlayerID,FullName and add it in items collection or use datatable MCAD

            A 1 Reply Last reply
            0
            • M Mohamad Al Husseiny

              Hi Alomgir Sorry i don't understand what you mean can you explain it more? What i want to say that he can create custom class which contain properties like PlayerID,FullName and add it in items collection or use datatable MCAD

              A Offline
              A Offline
              Alomgir Miah
              wrote on last edited by
              #6

              I understood your solution and I think it will work perfectly. This is just out of curiosity, I was just wondering if we can combine column values using DataView. Live Life King Size Alomgir Miah

              1 Reply Last reply
              0
              • B beqs

                Hope someone can help me. I want to add two values in a combobox. It's for players of a team. Now I have done it as follow with an DataSet: cbPlayers.DataSource = dsPlayers.Tables["Players"]; cbPlayers.ValueMember = "PlayerID"; cbPlayers.DisplayMember = "FullName"; This gives a combobox filled with only playernames But I also would like to include the team name behind the playername in this combobox. Who can help me out?:confused:

                M Offline
                M Offline
                Mohamad Al Husseiny
                wrote on last edited by
                #7

                You Can Create Expression Column That do that And bind DisplayMenmber to it somthing like that

                DataColumn dc=new DataColumn("Test",typeof(System.String)));
                dc.Expression="ContactName + (' ')+ CustomerID ";
                dataSet21.Customers.Columns.Add(dc);
                comboBox1.DataSource=dataSet21.Customers;
                comboBox1.DisplayMember=dataSet21.Customers.Columns["test"].Caption;
                comboBox1.ValueMember=dataSet21.Customers.CustomerIDColumn.Caption;
                

                MCAD

                B A 2 Replies Last reply
                0
                • M Mohamad Al Husseiny

                  You Can Create Expression Column That do that And bind DisplayMenmber to it somthing like that

                  DataColumn dc=new DataColumn("Test",typeof(System.String)));
                  dc.Expression="ContactName + (' ')+ CustomerID ";
                  dataSet21.Customers.Columns.Add(dc);
                  comboBox1.DataSource=dataSet21.Customers;
                  comboBox1.DisplayMember=dataSet21.Customers.Columns["test"].Caption;
                  comboBox1.ValueMember=dataSet21.Customers.CustomerIDColumn.Caption;
                  

                  MCAD

                  B Offline
                  B Offline
                  beqs
                  wrote on last edited by
                  #8

                  Thanx Mohamad. This is the solution for me! But one other thing This works for me: dc.Expression = "FullName + (' ')+ TeamName"; But I prefer an outcome like: FullName [TeamName] I tried the following but it gives an error: dc.Expression = "FullName + (' [')+ TeamName" + (']'); How can I achieve this the right way?

                  B 1 Reply Last reply
                  0
                  • B beqs

                    Thanx Mohamad. This is the solution for me! But one other thing This works for me: dc.Expression = "FullName + (' ')+ TeamName"; But I prefer an outcome like: FullName [TeamName] I tried the following but it gives an error: dc.Expression = "FullName + (' [')+ TeamName" + (']'); How can I achieve this the right way?

                    B Offline
                    B Offline
                    beqs
                    wrote on last edited by
                    #9

                    How stupid? I know it now: dc.Expression = "FullName + (' [')+ TeamName + (']')"; Thanx anyway...

                    1 Reply Last reply
                    0
                    • M Mohamad Al Husseiny

                      You Can Create Expression Column That do that And bind DisplayMenmber to it somthing like that

                      DataColumn dc=new DataColumn("Test",typeof(System.String)));
                      dc.Expression="ContactName + (' ')+ CustomerID ";
                      dataSet21.Customers.Columns.Add(dc);
                      comboBox1.DataSource=dataSet21.Customers;
                      comboBox1.DisplayMember=dataSet21.Customers.Columns["test"].Caption;
                      comboBox1.ValueMember=dataSet21.Customers.CustomerIDColumn.Caption;
                      

                      MCAD

                      A Offline
                      A Offline
                      Alomgir Miah
                      wrote on last edited by
                      #10

                      Thanks......... Live Life King Size Alomgir Miah

                      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