c# - Returning a list of cells if the previous column is checked in a DatagridView -
i've checked different codes i'm not able make effective use. i'm trying check value in 1st column boolean, if column checked need data in second column displayed in text/list box (if multiple boxes checked).
this how looks
datatable dt = new datatable(); dt.columns.add("methods",system.type.gettype("system.string")); dt.columns.add("select", system.type.gettype("system.boolean")); datarow dr = null; foreach (datagridviewrow row in datagridview1.rows) { //get appropriate cell using index, name or whatever , cast datagridviewcheckboxcell datagridviewcheckboxcell cell = row.cells["select"] datagridviewcheckboxcell; //compare true value because value isn't boolean if (cell.value == cell.truevalue) { listboxtemp.datasource = cell.value.tostring().tolist(); } //the value true }
so each selection made respective string in 'methods' has returned
thanks in advance
use row.cells["methods"]
other adjacent cell in row. can insert new list or else within foreach
loop.
ie. modifying existing code...
listbox listboxtemp = new listbox(); foreach (datagridviewrow row in datagridview1.rows) { datagridviewcheckboxcell cell = row.cells["select"] datagridviewcheckboxcell; if (cell.value == cell.truevalue) { listboxtemp.add(row.cells["methods"].value.tostring()); } }
you can stop , later resume painting of listbox
if you're iterating through large amount of rows. refer msdn example of this.
Comments
Post a Comment