Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 哪个接口实现使用(MyType)数组作为数据源?_.net_Linq_Datasource - Fatal编程技术网

.net 哪个接口实现使用(MyType)数组作为数据源?

.net 哪个接口实现使用(MyType)数组作为数据源?,.net,linq,datasource,.net,Linq,Datasource,我有一个LINQ查询,如下所示: allRecords = (From metaset In section.sets From metacell In metaset.cells Let attrib = metacell.attrib Order By attrib.attrib_name Select Attribute = attrib.

我有一个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()
它返回一个
数组。
当我写入
myDataGridView.DataSource=allRecords
时,网格正确填充。

但是,如果我修改查询以返回
CellDetail
对象数组,而不是

    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的数据源兼容?

DataGridView
绑定到属性,而不是字段。使它们成为属性

Public Class CellDetail    
    Public Property Attribute As String
    Public Property Type As String
    Public Property Col As Int32
    Public Property Row As Int32    
End Class
或者在C#中,这将是:

public class CellDetail {    
    public string Attribute {get;set;}
    public string Type {get;set;}
    public int Col {get;set;}
    public int Row {get;set;}
}

阅读datasource属性@Munchies的备注,它实际上不适用于这个问题;这两个源都是数组,数组实现了IList。这不是为什么它对一个有效而对另一个无效的原因。@MarcGravel是的,我没有正确阅读这个问题。谢谢@Marc Gravel。。。接受你的回答!