c# - How do we programatically add data from datagrid to list? -
i have following code, list not fetching exact values datagrid.
public list<double[]> extractgriddata(datagridview grid) { int numcols = grid.columns.count; list<double[]> list = new list<double[]>(); double[] cellsdata = new double[numcols]; foreach (datagridviewcell cell in grid.selectedcells) { if (cell.value != null) cellsdata[cell.rowindex] = convert.todouble(cell.value); list.add(cellsdata); } return list; }
i think need move:
double[] cellsdata = new double[numcols];
to within start of loop. @ moment, using same instance of array every iteration.
Comments
Post a Comment