c# - The multi-part identifier "System.Data.DataRowView" could not be bound -
this question has answer here:
i have table populate combobox1 , combobox1 should populate combobox2 , problem is. that's exception i'm getting
the multi-part identifier "system.data.datarowview" not bound.
code :
private void frm2_load(object sender, eventargs e) { //populate combobox1 sqldataadapter da = new sqldataadapter("select categoryid, name categories", clsmain.con); dataset ds = new dataset(); da.fill(ds); combobox1.datasource = ds.tables[0]; combobox1.displaymember = "name"; combobox1.valuemember = "categoryid"; } private void combobox1_selectedindexchanged(object sender, eventargs e) { //populate combobox2 sqldataadapter da = new sqldataadapter("select subcategoryid, name subcategories categoryid=" + combobox1.selectedvalue, clsmain.con); dataset ds = new dataset(); da.fill(ds); combobox2.datasource = ds.tables[0]; combobox2.displaymember = "name"; combobox2.valuemember = "subcategoryid"; }
this due loading second combobox while filling data in first combo.
can avoid error by:
1. use selectionchangecommitted event instead of selectedindexchanged event.
or
2. detach selected index change event, populate combobox, attach event again as:
private void frm2_load(object sender, eventargs e) { //detach event combobox1.selectedindexchanged -= combobox1_selectedindexchanged; //populate combobox1 sqldataadapter da = new sqldataadapter("select categoryid, name categories", clsmain.con); dataset ds = new dataset(); da.fill(ds); combobox1.datasource = ds.tables[0]; combobox1.displaymember = "name"; combobox1.valuemember = "categoryid"; //attach event again combobox1.selectedindexchanged += combobox1_selectedindexchanged; }
hopes you.
Comments
Post a Comment