c# - how do I make my DataGridView equal to my List<List<decimal>>? -
i have list of decimal lists, when filled it's grid...
2.0, 3.1, 4.0 3.2, 7.0, 1.4 6.0, 3.1, 8.8
the code list...
list<list<decimal>> rows = new list<list<decimal>>();
is there easy way make me datagridview display data, tried...
datagridview1.datasource = rows;
but did not work.
one way convert list of lists datatable
object , set datasource
property. here example of method such conversion:
public datatable createdatatable(list<list<decimal>> data) { datatable table = new datatable(); if (data.count == 0) return table; int fields = data[0].count; (int = 0; < fields; i++) { table.columns.add("column" + (i + 1), typeof (decimal)); } foreach (var list in data) { var row = table.newrow(); (int = 0; < fields; i++) { row.setfield(i, list[i]); } table.rows.add(row); } return table; }
and can set datasource
property this:
datagridview1.datasource = createdatatable(rows);
Comments
Post a Comment