How to put two columns in a combo box
-
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
-
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
-
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
your select query doesnt contans "
title
" but you have mapped the title tovalue
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
andValueMember
ascomboBox1.DisplayMember = "combinedCol";
comboBox1.ValueMember = "title"; -
your select query doesnt contans "
title
" but you have mapped the title tovalue
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
andValueMember
ascomboBox1.DisplayMember = "combinedCol";
comboBox1.ValueMember = "title";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.
-
your select query doesnt contans "
title
" but you have mapped the title tovalue
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
andValueMember
ascomboBox1.DisplayMember = "combinedCol";
comboBox1.ValueMember = "title";Thanks a lot
-
Thanks a lot
welcome :)
-
Thanks a lot