我正在尝试让 DataGrid 显示 object[][]
的内容。这将是只读的,所以我不关心通知更改或类似的事情。将 ItemSource
设置为 object[][]
只是在网格中显示 Array
的属性,并使用 List ;>
却做了同样的事情,这显然没有帮助。
每个一维数组的列数可以是任意的;我只是想为每行中的每个数组元素创建一个未命名的列。我该怎么做?
I'm trying to get a DataGrid to display the contents of an object[][]
. This'll be read-only so I don't care about notification changes or anything like that. Setting ItemSource
to an object[][]
simply displays the properties of Array
in the grid, and using List<List<object>>
instead does the same, which is decidedly unhelpful.
The number of columns in each 1d array can be arbitary; I simply want an unnamed column to be created for each array element in each row. How can I do this?
发布评论
评论(1)
请参阅我的答案 这个问题。这也将允许编辑值。由于您只是对显示它们感兴趣,如果不需要使用 DataGrid,那么使用 Jobi Joy 的答案可能会更容易。
制作该问题答案的简短版本。您需要一个 Ref 类
和一个辅助类来从二维数组中获取动态列
之后,您可以像这样使用 ItemsSource
See my answer in this question. This will also enable editing of the values. Since you're just interested in displaying them it might be easier to use the answer from Jobi Joy if using the DataGrid isn't a requirement.
To make a short version of the answer from that question. You'll need a Ref class
And a helper class to get dynamic columns from the 2d array
After that you can use ItemsSource like this