c# - DataGridViewComboBoxCell value is not valid -
can explain me how add datagridviewcomboboxcell datagridview? code this:
foreach(....){ datagridviewcomboboxcell cmb = new datagridviewcomboboxcell(); //cmb.item.add(.... datagridview.rows.add(new object[] {cmb,name,surname}); }
first cell in grid type of datagridviewcomboboxcolumn, tried changing cmb datagridviewcomboboxcolumn , still nothing.
i handeld dataerror dont "value not valid" error, comboboxes in datagridview empty.
ok, solved problem. seems have add values cells step step.
i'm going give general explanation because seems loot of people have problem this. let's have datagridview 3 columns, datagridviewtextboxcell, datagridviewcomboboxcolumn, datagridviewcheckboxcell in order. now, have make make 3 columns using desinger or otherwise wont work.
so want add specific values grid, each row representing lets person. in designer looks like
name phonenumbers married ..*.. |.....|..............|.........|....
so want add name textboxcell, list of phonenumbers comboboxcell , check checkboxcell if married. , repeat each person have in list.
here pseudocode:
foreach(person p in people.getall()){ /////make new cell each value datagridviewtextboxcell name= new datagridviewtextboxcell(); name.value = p.name; datagridviewtextboxcell phones= new datagridviewtextboxcell(); foreach(int pnumber in p.numbers){ phones.items.add(pnumber); } datagridviewcheckboxcell ismarried = new datagridviewcheckboxcell(); ismarried.value = p.married; ///////// make new row , add cells datagridviewrow row = new datagridviewrow(); row .cells.add(name); row .cells.add(phones); row .cells.add(ismarried ); ///// add entire row data grid datagridview.rows.add(row); }
just repeat, first have add columns grid using designer , when add cells row in code has in exacly same order seen in designer.
Comments
Post a Comment