c# - First combobox item missing after combobox filled with datatable -
i have combobox
on form , datatable
. combobox
filled row values fro datatable
. before add combobox
item called (new) first option of combobox
in case user add new item.
but when combobox
filled, (new) not show reason.
string query = "select id,name,text apsissms order id desc"; oledbdataadapter da = new oledbdataadapter(query, conn); conn.open(); da.fill(dtsmsmessages); combosmsmessages.items.add(new comboboxitem() { text = "(new)", value = "-1" }); if (dtsmsmessages.rows != null && dtsmsmessages.rows.count > 0) { combosmsmessages.items.clear(); (int = 0; < dtsmsmessages.rows.count; i++) { comboboxitem item = new comboboxitem() { text = dtsmsmessages.rows[i]["name"].tostring(), value = dtsmsmessages.rows[i]["id"].tostring() }; combosmsmessages.items.add(item); } } combosmsmessages.selectedindex = 0;
combosmsmessages.items.clear(); clear items add combosmsmessages.items.add(new comboboxitem() { text = "(new)", value = "-1" }); after cleared combobox code should
string query = "select id,name,text apsissms order id desc"; oledbdataadapter da = new oledbdataadapter(query, conn); conn.open(); da.fill(dtsmsmessages); if (dtsmsmessages.rows != null && dtsmsmessages.rows.count > 0) { combosmsmessages.items.clear(); combosmsmessages.items.add(new comboboxitem() { text = "(new)", value = "-1" }); (int = 0; < dtsmsmessages.rows.count; i++) { comboboxitem item = new comboboxitem() { text = dtsmsmessages.rows[i]["name"].tostring(), value = dtsmsmessages.rows[i]["id"].tostring() }; combosmsmessages.items.add(item); } } combosmsmessages.selectedindex = -1;
Comments
Post a Comment