.NET 数据展示与绑定技术详解
在 .NET 开发中,数据的展示和绑定是非常重要的环节。下面将详细介绍 DataGrid 相关接口、样式设置、数据绑定以及 Visual Studio.NET 中数据访问的相关内容。
1. IListSource 和 IList 接口
DataGrid 支持实现了 IListSource 或 IList 接口的对象。IListSource 只有一个方法 GetList(),它返回一个 IList 接口。而 IList 接口则更有趣,运行时中有大量的类实现了该接口,例如 Array、ArrayList 和 StringCollection。
需要注意的是,当使用 IList 时,如果使用 StringCollection 作为 DataGrid 的数据源,网格中显示的将是字符串的长度,而不是预期的项文本。
2. DataGrid 类层次结构
DataGrid 由零个或多个 DataGridTableStyles 组成,而这些样式又由零个或多个 DataGridColumnStyles 组成。可以通过 DataGridCell 结构体访问网格中的特定单元格。
以下是 DataGrid 主要部分的类层次结构:
Object
MarshalByRefObject
ValueType
ComponentModel.Component
Windows.Forms.DataGridCell
Windows.Forms.Control
Windows.Forms.DataGridColumnStyle
Windo