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;
你自己看把