VS的控件真是不好用,好不容易才搞定DataGrid

摘一段自定义DataGrid样式的贴上来共享:

private void RunProc_Load(object sender, System.EventArgs e)
{
procData=new SqlDataProvider(ConnectionString).GetProcColumn(ProcName);
procData.Tables[0].Columns.Add("parmvalue");
procData.Tables[0].Columns.Add("Direction");
procData.Tables[0].Columns.Remove("isoutparam");
AddDataGrid(new DataView(procData.Tables[0]));
}

private void AddDataGrid(DataView dv)
{
DataGridTextBoxColumn TxtCol =new DataGridTextBoxColumn();
dataGrid1.TableStyles.Clear();
dataGrid1.DataSource=dv;
DataGridTableStyle ts= new DataGridTableStyle();
ts.MappingName ="SqlBuilder";
dv.AllowNew=false;
dv.AllowDelete=false;
dv.AllowEdit=false;

TxtCol =new DataGridTextBoxColumn();
TxtCol.MappingName ="name";
TxtCol.HeaderText ="参数名";
TxtCol.Width =100;
TxtCol.ReadOnly=true;
ts.GridColumnStyles.Add(TxtCol);

TxtCol =new DataGridTextBoxColumn();
TxtCol.MappingName ="xtypename";
TxtCol.HeaderText ="参数类型";
TxtCol.Width =75;
TxtCol.ReadOnly=true;
ts.GridColumnStyles.Add(TxtCol);

TxtCol =new DataGridTextBoxColumn();
TxtCol.MappingName ="length";
TxtCol.HeaderText ="参数长度";
TxtCol.Width =75;
TxtCol.ReadOnly=true;
ts.GridColumnStyles.Add(TxtCol);

TxtCol =new DataGridTextBoxColumn();
TxtCol.MappingName ="Direction";
TxtCol.HeaderText ="传递方向";
TxtCol.Width =75;
TxtCol.ReadOnly=true;
ts.GridColumnStyles.Add(TxtCol);

dv.AllowEdit=true;
TxtCol =new DataGridTextBoxColumn();
TxtCol.MappingName ="parmvalue";
TxtCol.HeaderText ="测试值";
TxtCol.Width =100;
TxtCol.ReadOnly=false;
ts.GridColumnStyles.Add(TxtCol);

dataGrid1.TableStyles.Add(ts);

}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus