DataGrid自己绑定,如何针对某一列控制该列的style?
取得DataSet后,直接绑定到DataGrid1,
有个字段名为"TypeName",我如何在DataGrid1中找到该列,
并设置该列标题为中文名“类型名称”,显示的宽度为200px。
该如何写代码?
问题点数:50、回复次数:7Top
1 楼meixiaofeng(yesmsn)回复于 2005-06-01 11:14:59 得分 25
private void hideColumn()
{
// Set the DataGridTableStyle.MappingName property
// to the table in the data source to map to.
ts.MappingName = dataGrid1.DataMember;
// Add it to the datagrid's TableStyles collection
dataGrid1.TableStyles.Add(ts);
// Hide the first column (index 0)
dataGrid1.TableStyles[0].GridColumnStyles[0].Width = 0;
}
动态的添加列,然后设置其属性Top
2 楼tangyong12(海洋之星)回复于 2005-06-01 11:17:27 得分 25
private void SetDataGridTableStyle(DataSet ds,DataGrid dataGrid)
{
dataGrid.TableStyles.Clear();
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = ds.Tables[0].TableName;
foreach(DataColumn column in ds.Tables[0].Columns)
{
DataGridTextBoxColumn textColumn = new DataGridTextBoxColumn();
if(column.Caption == "TypeName")
{
textColumn.MappingName = column.Caption;
textColumn.HeaderText = "类型名称";
textColumn.Width = 200;
}
else
{
textColumn.MappingName = column.Caption;
textColumn.HeaderText = column.Caption;
}
tableStyle.GridColumnStyles.Add(columnName);
}
dataGrid.TableStyles.Add(tableStyle);
}Top
3 楼COpyFRee(NULL)回复于 2005-06-01 12:36:16 得分 0
同上Top
4 楼liuchengit(有事您说话)回复于 2005-06-01 12:48:03 得分 0
datagrid样式据说是最多的,,看看帮助帮Top
5 楼cndsn(磐石)回复于 2005-06-02 11:45:36 得分 0
动态绑定好象不行哦,因为我的列是不确定的,怎么绑啊?
To tangyong12(海洋之星) :
你给的是WinForm 的代码,有没有webform的代码?
大家帮忙啊!
Top
6 楼wgif_79(冰雹)回复于 2005-06-02 11:54:41 得分 0
在DataItemBind中设置,查查帮助Top
7 楼cndsn(磐石)回复于 2005-06-02 12:10:29 得分 0
找了还是不会设置,
热心朋友请帮忙!Top




