DOODpls DOODpls - 1 year ago 107
C# Question

Add "---OTHERS---" on top of mysql-populated combobox

I am having a hard time figuring this out.. I want to add a

text on top of my
, but my
is populated with MySQL:

conDatabase = new MySqlConnection(constring);
MySqlCommand cmdDatabase = new MySqlCommand("select distinct item_type from Company_db.inventory", conDatabase);
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmdDatabase;
DataSet dbdataset = new DataSet();
cbPart.DataSource = dbdataset.Tables[0];
cbPart.DisplayMember = "item_type";
catch (Exception ex)

Answer Source

You need to add the extra item to the rows collection of the datatable before binding it to the datasource.


DataTable dt = dbdataset.Tables[0];
DataRow row = dt.NewRow();
row.ItemArray = new object[] {"--OTHERS--"};
dt.Rows.InsertAt(row, 0);

cbPart.DataSource = dt;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download