最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何定制你自己的DataGrid
时间:2022-07-02 11:35:17 编辑:袖梨 来源:一聚教程网
如何定制你自己的DataGrid
--------------------------------------------------------------------------------
作者:胡晓东
下面的例子显示了如何定制DataGrid,包括如何绑定一个DataTable到一个DataGrid,以及如何隐藏DataGrid中的一些列。
首先,如果你只设置DataGrid的DataSource属性是一个DataTable,那么DataGrid的TableStyle将是DefaultTableStyle,它的TableStyle.Count属性是零。所以,如果你想让你的DataGrid有个不同的table style,你必须添加你自己的table style。
下面的例子设置了一个DataGrid的data source属性,然后声明一个新的DataGridTableStyle和四个DataGridColumnStyles。这是因为在_periodData.Tables [AccountingPeriodData.AccountingPeriod_TABLE] 中有六个字段,但我只想显示四个,而且第一个必须是只读的,当然我想改变每个字段的Header Text,所以我用这个函数来实现它。注意,我们不能把HeaderText设置成一个字符串常量,我们应该从源文件中得到它。
顺便说一下,我声明了四个DataGridColumnStyle对象,但将它们更新为DataGridTextBoxColumn,这意味着你也可以将它们更新为一个DataGidBoolColumn。你当然应该知道原因啦。:-)// Initialize DataGrid when the form is opened.
private void InitializeDataGrid()
{
// set the DataGrid's datasource to a DataTable
dtgPeriods.DataSource = _periodData.Tables
[AccountingPeriodData.AccountingPeriod_TABLE];
// Create a DataGridTableStyle and set its MappingName is Accounting_TABLE
DataGridTableStyle mydtgTableStyle = new DataGridTableStyle();
mydtgTableStyle.MappingName = AccountingPeriodData.AccountingPeriod_TABLE;
// Create DataGridColumnStyles, set their properties
--------------------------------------------------------------------------------
作者:胡晓东
下面的例子显示了如何定制DataGrid,包括如何绑定一个DataTable到一个DataGrid,以及如何隐藏DataGrid中的一些列。
首先,如果你只设置DataGrid的DataSource属性是一个DataTable,那么DataGrid的TableStyle将是DefaultTableStyle,它的TableStyle.Count属性是零。所以,如果你想让你的DataGrid有个不同的table style,你必须添加你自己的table style。
下面的例子设置了一个DataGrid的data source属性,然后声明一个新的DataGridTableStyle和四个DataGridColumnStyles。这是因为在_periodData.Tables [AccountingPeriodData.AccountingPeriod_TABLE] 中有六个字段,但我只想显示四个,而且第一个必须是只读的,当然我想改变每个字段的Header Text,所以我用这个函数来实现它。注意,我们不能把HeaderText设置成一个字符串常量,我们应该从源文件中得到它。
顺便说一下,我声明了四个DataGridColumnStyle对象,但将它们更新为DataGridTextBoxColumn,这意味着你也可以将它们更新为一个DataGidBoolColumn。你当然应该知道原因啦。:-)// Initialize DataGrid when the form is opened.
private void InitializeDataGrid()
{
// set the DataGrid's datasource to a DataTable
dtgPeriods.DataSource = _periodData.Tables
[AccountingPeriodData.AccountingPeriod_TABLE];
// Create a DataGridTableStyle and set its MappingName is Accounting_TABLE
DataGridTableStyle mydtgTableStyle = new DataGridTableStyle();
mydtgTableStyle.MappingName = AccountingPeriodData.AccountingPeriod_TABLE;
// Create DataGridColumnStyles, set their properties
相关文章
- 雪球官网网页版入口-雪球财经官网网页版 01-30
- 拷贝漫画2.1.0.4安卓下载入口-拷贝漫画2.1.0.4最新版本免费下载 01-30
- 有罪之身全集资源在线看-有罪之身最新一集免费观看入口地址 01-30
- 永劫无间云游戏入口-永劫无间无限畅玩云端官网 01-30
- 蓝莓影院官网入口-2026蓝莓影院电视剧免费观看 01-30
- 找靓机网页版直达-找靓机官网正版入口 01-30