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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -