代码之家  ›  专栏  ›  技术社区  ›  Brendan

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

  •  5
  • Brendan  · 技术社区  · 17 年前

    DataGridView可以绑定到具有特定接口集的对象(例如IList、IListSource等),因此理论上我可以创建一个类来封装二维数组并实现其中一个接口。然而,令人费解的是,接口规范似乎只满足于一维数组-请参阅 IList

    更新: 从答案来看,IList似乎满足于对象列表。那么有没有办法将任意大小的多维数组(float)绑定到DataGridView?或者可以使用DataGridView本身作为存储浮动的数据结构吗?

    3 回复  |  直到 17 年前
        1
  •  3
  •   Marc Gravell    17 年前

    我以前做过这样的事, here -在 IList ;可能有用。

        2
  •  2
  •   BFree    17 年前

    这样想吧。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"])
    

    如果这没有任何意义,那么我不理解你的问题,我道歉。

        3
  •  2
  •   Darin Dimitrov    17 年前

    有一个很好的 article on CodeProject 演示如何将二维数组绑定到DataGridView。