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. How to put two columns in a combo box

How to put two columns in a combo box

Scheduled Pinned Locked Moved C#
csharpmysqlsysadminhelptutorial
7 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.
  • U Offline
    U Offline
    User 12245067
    wrote on last edited by
    #1

    Please help. How to put two columns in a combo box (list Box, text box:mad. I work with VS2015, c# and MySql 5.7. Attached part of the code. private void comboBox1_Click (object sender, EventArgs e) { MySqlConnection conn; myConnectionString = pwput; conn = new MySql.Data.MySqlClient.MySqlConnection (); conn.ConnectionString = myConnectionString; try { conn.Open (); } catch (MySqlException ex) { switch (ex.Number) { case 0: MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER, CLOSE PROGRAM TO TAKE A REPLY"); Close (); break; case 1042: MessageBox.Show ("NOT ACTIVE SERVER, SUBSCRIBE SERVER PA REPEAT CONNECTING"); Close (); break; } conn.Close (); } if (conn.State! = ConnectionState.Open) { MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER \ r \ n CLOSE PROGRAM TO TAKE READY \ r \ n"); } else { AutoCompleteStringCollection kontoopis = new AutoCompleteStringCollection (); string wnadidok = "SELECT idkonto, FROM account name"; loadingData = false; DataTable dtkon = new DataTable (); dtkon.Columns.Add (); dtkon.Columns.Add (); MySqlDataAdapter mdkon = new MySqlDataAdapter (wnadidok, conn); mdkon.Fill (dtkon); loadingData = true; comboBox1.DataSource = dtkon; // which field is shown in the table below comboBox1.DisplayMember = "idkonto"; comboBox1.ValueMember = "idkonto"; comboBox1.DisplayMember = "title"; comboBox1.ValueMember = "title"; comboBox1.SelectedIndex = -1; comboBox1.Text = ""; loadingData = false; } conn.Close (); } Thank you

    L K 2 Replies Last reply
    0
    • U User 12245067

      Please help. How to put two columns in a combo box (list Box, text box:mad. I work with VS2015, c# and MySql 5.7. Attached part of the code. private void comboBox1_Click (object sender, EventArgs e) { MySqlConnection conn; myConnectionString = pwput; conn = new MySql.Data.MySqlClient.MySqlConnection (); conn.ConnectionString = myConnectionString; try { conn.Open (); } catch (MySqlException ex) { switch (ex.Number) { case 0: MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER, CLOSE PROGRAM TO TAKE A REPLY"); Close (); break; case 1042: MessageBox.Show ("NOT ACTIVE SERVER, SUBSCRIBE SERVER PA REPEAT CONNECTING"); Close (); break; } conn.Close (); } if (conn.State! = ConnectionState.Open) { MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER \ r \ n CLOSE PROGRAM TO TAKE READY \ r \ n"); } else { AutoCompleteStringCollection kontoopis = new AutoCompleteStringCollection (); string wnadidok = "SELECT idkonto, FROM account name"; loadingData = false; DataTable dtkon = new DataTable (); dtkon.Columns.Add (); dtkon.Columns.Add (); MySqlDataAdapter mdkon = new MySqlDataAdapter (wnadidok, conn); mdkon.Fill (dtkon); loadingData = true; comboBox1.DataSource = dtkon; // which field is shown in the table below comboBox1.DisplayMember = "idkonto"; comboBox1.ValueMember = "idkonto"; comboBox1.DisplayMember = "title"; comboBox1.ValueMember = "title"; comboBox1.SelectedIndex = -1; comboBox1.Text = ""; loadingData = false; } conn.Close (); } Thank you

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

      Multi Column ComboBox[^]

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      U 1 Reply Last reply
      0
      • U User 12245067

        Please help. How to put two columns in a combo box (list Box, text box:mad. I work with VS2015, c# and MySql 5.7. Attached part of the code. private void comboBox1_Click (object sender, EventArgs e) { MySqlConnection conn; myConnectionString = pwput; conn = new MySql.Data.MySqlClient.MySqlConnection (); conn.ConnectionString = myConnectionString; try { conn.Open (); } catch (MySqlException ex) { switch (ex.Number) { case 0: MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER, CLOSE PROGRAM TO TAKE A REPLY"); Close (); break; case 1042: MessageBox.Show ("NOT ACTIVE SERVER, SUBSCRIBE SERVER PA REPEAT CONNECTING"); Close (); break; } conn.Close (); } if (conn.State! = ConnectionState.Open) { MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER \ r \ n CLOSE PROGRAM TO TAKE READY \ r \ n"); } else { AutoCompleteStringCollection kontoopis = new AutoCompleteStringCollection (); string wnadidok = "SELECT idkonto, FROM account name"; loadingData = false; DataTable dtkon = new DataTable (); dtkon.Columns.Add (); dtkon.Columns.Add (); MySqlDataAdapter mdkon = new MySqlDataAdapter (wnadidok, conn); mdkon.Fill (dtkon); loadingData = true; comboBox1.DataSource = dtkon; // which field is shown in the table below comboBox1.DisplayMember = "idkonto"; comboBox1.ValueMember = "idkonto"; comboBox1.DisplayMember = "title"; comboBox1.ValueMember = "title"; comboBox1.SelectedIndex = -1; comboBox1.Text = ""; loadingData = false; } conn.Close (); } Thank you

        K Offline
        K Offline
        Karthik_Mahalingam
        wrote on last edited by
        #3

        your select query doesnt contans "title" but you have mapped the title to value member the below lines repeating twice, however the compiler will takes only the latest assigned values comboBox1.DisplayMember = "idkonto"; comboBox1.ValueMember = "idkonto";

        comboBox1.DisplayMember = "title";
        comboBox1.ValueMember = "title";

        try concatenating the two columns in the select query as

        string wnadidok = "SELECT idkonto + ' ' + title as combinedCol , title FROM [account name]"; // take care of this

        and change the DisplayMember and ValueMember as

        comboBox1.DisplayMember = "combinedCol";
        comboBox1.ValueMember = "title";

        P U 2 Replies Last reply
        0
        • K Karthik_Mahalingam

          your select query doesnt contans "title" but you have mapped the title to value member the below lines repeating twice, however the compiler will takes only the latest assigned values comboBox1.DisplayMember = "idkonto"; comboBox1.ValueMember = "idkonto";

          comboBox1.DisplayMember = "title";
          comboBox1.ValueMember = "title";

          try concatenating the two columns in the select query as

          string wnadidok = "SELECT idkonto + ' ' + title as combinedCol , title FROM [account name]"; // take care of this

          and change the DisplayMember and ValueMember as

          comboBox1.DisplayMember = "combinedCol";
          comboBox1.ValueMember = "title";

          P Offline
          P Offline
          Pooja Dalvi
          wrote on last edited by
          #4

          Hello, I also recognized this one line when I was looking at your post. Thanks for the code. If you really know about the MiniBlog.Core built using ASP.NET Core 2.0 then please let me know. Thanks in advance, Good Day & Keep Coding.

          1 Reply Last reply
          0
          • K Karthik_Mahalingam

            your select query doesnt contans "title" but you have mapped the title to value member the below lines repeating twice, however the compiler will takes only the latest assigned values comboBox1.DisplayMember = "idkonto"; comboBox1.ValueMember = "idkonto";

            comboBox1.DisplayMember = "title";
            comboBox1.ValueMember = "title";

            try concatenating the two columns in the select query as

            string wnadidok = "SELECT idkonto + ' ' + title as combinedCol , title FROM [account name]"; // take care of this

            and change the DisplayMember and ValueMember as

            comboBox1.DisplayMember = "combinedCol";
            comboBox1.ValueMember = "title";

            U Offline
            U Offline
            User 12245067
            wrote on last edited by
            #5

            Thanks a lot

            K 1 Reply Last reply
            0
            • U User 12245067

              Thanks a lot

              K Offline
              K Offline
              Karthik_Mahalingam
              wrote on last edited by
              #6

              welcome :)

              1 Reply Last reply
              0
              • L Lost User

                Multi Column ComboBox[^]

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                U Offline
                U Offline
                User 12245067
                wrote on last edited by
                #7

                Thanks a lot

                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