c# - How to cope with bidimensional data display AND edit -
i have display double x,y offset in datagrid. in mind (done excel , photoshop):
allowing users change offset value. having numbers printed on rows , columns.
at moment offset structure is:
public point[,] pointmatrix;
but when associate datagrid error:
so perhaps bidimensional array not right type. hint how it?
unfortunately can't set itemsource
of datagrid
2d array, need either bind list<list<point>>
of datatable
, using datatable
easier since won't require changes, add following converter method convert 2d array datatable:
private dataview convertfrommatrixtodatatable(point[,] matrix) { var mydatatable = new datatable(); (int = 0; < matrix.getlength(0); i++) { mydatatable.columns.add(i.tostring()); } (int j = 0; j < matrix.getlength(1); j++) { var row = mydatatable.newrow(); (int = 0; < matrix.getlength(0); i++) { row[i] = matrix[i, j]; } mydatatable.rows.add(row); } return mydatatable.defaultview; }
then use affect datagrid
's itemsource
:
dtgnests.itemssource = convertfrommatrixtodatatable(pointmatrix);
Comments
Post a Comment