人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

如何定制你自己的DataGrid

如何定制你自己的DataGrid

更新時間:2022-07-04 文章作者:未知 信息來源:網絡 閱讀次數:

如何定制你自己的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
// Add these DataGridCollumnStyles into
the DataGridTableStyle defined above one by one
DataGridColumnStyle periodCodeStyle = new DataGridTextBoxColumn();
periodCodeStyle.MappingName = AccountingPeriodData.Period_FIELD;
periodCodeStyle.HeaderText = "會計期別";
periodCodeStyle.ReadOnly = true;
mydtgTableStyle.GridColumnStyles.Add(periodCodeStyle);

DataGridColumnStyle startDateStyle = new DataGridTextBoxColumn();
startDateStyle.MappingName = AccountingPeriodData.StartDate_FIELD;
startDateStyle.HeaderText = "期初日期";
mydtgTableStyle.GridColumnStyles.Add(startDateStyle);

DataGridColumnStyle endDateStyle = new DataGridTextBoxColumn();
endDateStyle.MappingName = AccountingPeriodData.EndDate_FIELD;
endDateStyle.HeaderText = "期末日期";
mydtgTableStyle.GridColumnStyles.Add(endDateStyle);

DataGridColumnStyle openStyle = new DataGridTextBoxColumn();
openStyle.MappingName = AccountingPeriodData.Open_FIELD;
openStyle.HeaderText = "期別開關";
mydtgTableStyle.GridColumnStyles.Add(openStyle);

// Add the DataGridTableStyle into the DataGrid's datasource.
dtgPeriods.TableStyles.Add(mydtgTableStyle);
}


溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 应城市| 通道| 聂荣县| 泰宁县| 镇巴县| 塔河县| 巨野县| 海林市| 汽车| 云南省| 上饶市| 柘荣县| 万全县| 桂平市| 佳木斯市| 梅州市| 德化县| 深圳市| 芜湖县| 修文县| 唐海县| 磐安县| 扎赉特旗| 光山县| 华坪县| 阳泉市| 泰兴市| 宜章县| 阳原县| 梁河县| 湄潭县| 吴川市| 建昌县| 娱乐| 镇巴县| 东台市| 都安| 华亭县| 四会市| 陇南市| 监利县|