Seems like this would be easy to do, but it appears its not so simple. I have a 2d array of floats or ints and I'd like to display it in a grid like control so it acts similar to Excel in regards to being able to move around with the arrow keys, tab keys, etc. The size of the array will vary. This comes close, but works well only for displaying:
Asked
Active
Viewed 5,191 times
6
-
I can't try it at the moment...but if you just replace the button with a text box you should be able to edit the array, too. But I'm not sure how well keyboard navigation will work. – Daniel Brückner Oct 21 '10 at 20:53
-
Yes, that will work as long as you also create a DependencyObject wrapper for int or float. However, like you mentioned this does not solve all the navigation and selection abilities that come with a datagrid. – AKoran Oct 21 '10 at 21:20
-
Updated my answer to use the DataGrid – Fredrik Hedblad Oct 23 '10 at 11:00
1 Answers
9
I found the easiest way would be to use datatables and create one dynamically :
DataTable dt = new DataTable();
int nbColumns = 10;
int nbRows = 5;
for (int i = 0; i < nbColumns; i++)
{
dt.Columns.Add(i.ToString(), typeof(double));
}
for (int row = 0; row < nbRows; row++)
{
DataRow dr = dt.NewRow();
for (int col = 0; col < nbColumns; col++)
{
dr[col] = col;
}
dt.Rows.Add(dr);
}
myDataGrid.ItemsSource = dt.DefaultView;
Of course this is just a random table, you can load your 2d or Xd array in your DataTable. And also, you don't have to implement IEnumerable and stuff...

user627283
- 533
- 5
- 19