是新手。所以用比较复杂的程序估计是看不懂了。。所以找简单点的。
资料好多,去BAIDU下看看,
1、新建立一个 DataGridTableStyle
DataGridTableStyle dtstyle= new DataGridTableStyle();
2、绑定数据源
dtstyle.MappingName=TableName;
3、设定
dg.TableStyles.Clear();
dg.TableStyles.Add(dtstyle);
dg.TableStyles[TableName].GridColumnStyles[ColumnName].Width=200;
DataTable dt = new DataTable("SourceTable");
DataRow dr;
dt.Columns.Add(new DataColumn("Date",typeof(string)));
dt.Columns.Add(new DataColumn("Cost",typeof(string)));
dt.Columns.Add(new DataColumn("Reason",typeof(string)));
//dt.Columns.Add(new DataColumn("ni",typeof(string)));//加列
for(int i = 0 ;i < list1.Count;i++)
{
Info info = (Info)(list1[i]);
dr = dt.NewRow();
dr[0] = info.DATE;
dr[1] = info.COST;
dr[2] = info.REASON;
//dr[3] = int.Parse(info.COST)*10;//值
dt.Rows.Add(dr);
}
//dt.TableName = "SourceTable";
DataView dv = new DataView(dt);
DataGridTableStyle dss = new DataGridTableStyle ();
dss.MappingName = "SourceTable";
infodataGrid.CaptionText = " 信息如下: ";//表头
infodataGrid.DataSource = dv;
infodataGrid.TableStyles .Clear ();
infodataGrid.TableStyles .Add (dss);
infodataGrid.TableStyles[0].GridColumnStyles["Date"].Width = 100;
infodataGrid.TableStyles[0].GridColumnStyles["Cost"].Width = 100;
infodataGrid.TableStyles[0].GridColumnStyles["Reason"].HeaderText ="原因";
infodataGrid.TableStyles [0].GridColumnStyles["Reason"].Width = 208;
你自己看把