用列样式columnstyle
#region 角色信息Datagrid样式
private void dgColumnStyle_Role(bool editFlag)
{
//声明DataGridTableStyle
DataGridTableStyle myTableStyle = new DataGridTableStyle( );
myTableStyle.MappingName = "XT_QX_JS_TB";
//声明DataGridColumnStyle1
DataGridTextBoxColumn ColumnStyle1 = new DataGridTextBoxColumn();
ColumnStyle1.MappingName = "QX_JS_BM";
ColumnStyle1.HeaderText = "编号";
ColumnStyle1.Width = 0;
ColumnStyle1.ReadOnly = true;
ColumnStyle1.Format= "yyyy年MM月dd日";//这列如果是日期类型可以用指定日期格式显示日期值。
myTableStyle.GridColumnStyles.Add(ColumnStyle1);
//声明DataGridColumnStyle2
DataGridTextBoxColumn ColumnStyle2 = new DataGridTextBoxColumn();
ColumnStyle2.MappingName = "QX_JS_MC";
ColumnStyle2.HeaderText = "名称";
ColumnStyle2.Width = 120;
ColumnStyle2.NullText="";
myTableStyle.GridColumnStyles.Add(ColumnStyle2);
//声明DataGridColumnStyle3
DataGridTextBoxColumn ColumnStyle3 = new DataGridTextBoxColumn();
ColumnStyle3.MappingName = "QX_JS_MS";
ColumnStyle3.HeaderText = "描述";
ColumnStyle3.Width = 120;
ColumnStyle3.NullText="";
myTableStyle.GridColumnStyles.Add(ColumnStyle3);
//声明DataGridColumnStyle5
DataGridBoolColumn ColumnStyle5 = new DataGridBoolColumn();
ColumnStyle5.MappingName = "QX_JS_SFYX";
ColumnStyle5.HeaderText = "有效";
ColumnStyle5.AllowNull = false;
ColumnStyle5.TrueValue = (Decimal)1;
ColumnStyle5.FalseValue = (Decimal)0;
ColumnStyle5.Width = 40;
myTableStyle.GridColumnStyles.Add(ColumnStyle5);
//声明DataGridColumnStyle4
DataGridTextBoxColumn ColumnStyle4 = new DataGridTextBoxColumn();
ColumnStyle4.MappingName = "QX_JS_XSSX";
ColumnStyle4.HeaderText = "顺序";
ColumnStyle4.Width = 40;
myTableStyle.GridColumnStyles.Add(ColumnStyle4);
dataGridMain.TableStyles.Clear();
dataGridMain.TableStyles.Add( myTableStyle );
#region 角色信息Datagrid样式
private void dgColumnStyle_Role(bool editFlag)
{
//声明DataGridTableStyle
DataGridTableStyle myTableStyle = new DataGridTableStyle( );
myTableStyle.MappingName = "XT_QX_JS_TB";
//声明DataGridColumnStyle1
DataGridTextBoxColumn ColumnStyle1 = new DataGridTextBoxColumn();
ColumnStyle1.MappingName = "QX_JS_BM";
ColumnStyle1.HeaderText = "编号";
ColumnStyle1.Width = 0;
ColumnStyle1.ReadOnly = true;
ColumnStyle1.Format= "yyyy年MM月dd日";//这列如果是日期类型可以用指定日期格式显示日期值。
myTableStyle.GridColumnStyles.Add(ColumnStyle1);
//声明DataGridColumnStyle2
DataGridTextBoxColumn ColumnStyle2 = new DataGridTextBoxColumn();
ColumnStyle2.MappingName = "QX_JS_MC";
ColumnStyle2.HeaderText = "名称";
ColumnStyle2.Width = 120;
ColumnStyle2.NullText="";
myTableStyle.GridColumnStyles.Add(ColumnStyle2);
//声明DataGridColumnStyle3
DataGridTextBoxColumn ColumnStyle3 = new DataGridTextBoxColumn();
ColumnStyle3.MappingName = "QX_JS_MS";
ColumnStyle3.HeaderText = "描述";
ColumnStyle3.Width = 120;
ColumnStyle3.NullText="";
myTableStyle.GridColumnStyles.Add(ColumnStyle3);
//声明DataGridColumnStyle5
DataGridBoolColumn ColumnStyle5 = new DataGridBoolColumn();
ColumnStyle5.MappingName = "QX_JS_SFYX";
ColumnStyle5.HeaderText = "有效";
ColumnStyle5.AllowNull = false;
ColumnStyle5.TrueValue = (Decimal)1;
ColumnStyle5.FalseValue = (Decimal)0;
ColumnStyle5.Width = 40;
myTableStyle.GridColumnStyles.Add(ColumnStyle5);
//声明DataGridColumnStyle4
DataGridTextBoxColumn ColumnStyle4 = new DataGridTextBoxColumn();
ColumnStyle4.MappingName = "QX_JS_XSSX";
ColumnStyle4.HeaderText = "顺序";
ColumnStyle4.Width = 40;
myTableStyle.GridColumnStyles.Add(ColumnStyle4);
dataGridMain.TableStyles.Clear();
dataGridMain.TableStyles.Add( myTableStyle );