我可以将多维数据绑定到C#和.NET中的DataGridView吗?

Bre*_*dan 5 .net c# datagridview interface visual-studio

我正在寻找一个应用程序,其中包含从DataGridView子类化的工作表.用户可以将类似CSV的数据粘贴(或导入)到工作表中,它将反映在内存中的数据结构中 - 我的第一个猜测是浮点数的二维数组.

DataGridView可以绑定到具有一组接口的对象(即IList,IListSource等),因此,理论上我可以创建一个封装2D数组并实现其中一个接口的类.然而,令人费解的是,界面规格似乎只适合1维阵列 - 例如见IList.到底是怎么回事?!

更新:从答案来看,似乎IList迎合了对象列表.有没有办法将任意大小(浮点数)的多维数组绑定到DataGridView?或者可以使用DataGridView本身作为存储浮点数据的数据结构?

BFr*_*ree 2

这样想吧。IList 可以是对象的集合。每个对象都可以有多个属性。本质上,这就像一个二维数组。第一个维度是对象及其所有属性,第二个维度是所述对象的集合。像这样的东西:

list[0] --> Name, (think of this as list[0]["Name"])
            Age, (think of this as list[0]["Age"])
            Height  (think of this as list[0]["Height"])


list[1] --> Name, (think of this as list[1]["Name"])
            Age, (think of this as list[1]["Age"])
            Height  (think of this as list[1]["Height"])
Run Code Online (Sandbox Code Playgroud)

因此,在您的情况下,如果列是固定的,那么您只需要一个封装所有这些字段的对象,然后拥有这些对象的集合,然后将其绑定到 DataGridView。

如果这没有任何意义,那么我不明白你的问题,我很抱歉。