我有一个 LINQ 查询,如下所示:
allRecords = (From metaset In section.sets
From metacell In metaset.cells
Let attrib = metacell.attrib
Order By attrib.attrib_name
Select Attribute = attrib.attrib_name,
Type = attrib.attrib_name,
Col = metacell.column,
Row = metacell.row
).ToArray()
它返回一个<anonymous type>
数组。
当我写时myDataGridView.DataSource = allRecords
,网格会正确填充。
但是,如果我修改查询以返回对象数组CellDetail
,而不是<anonymous type>
:
allRecords = (From metaset In section.sets
From metacell In metaset.cells
Let attrib = metacell.attrib
Order By attrib.attrib_name
Select New CellDetail With {
.Attribute = attrib.attrib_name,
.Type = attrib.attrib_name,
.Col = metacell.column,
.Row = metacell.row
).ToArray()
哪里CellDetail
是这么定义的:
Public Class CellDetail
Public Attribute As String
Public Type As String
Public Col As Int32
Public Row As Int32
End Class
DataGridView 没有找到兼容的数据并且什么也不显示!
我应该实现一个 .Net 接口以使CellDetail
类与 DataGridView 的 DataSource 兼容吗?