DataGridTableStyle dgStyle = new DataGridTableStyle();
dgStyle.MappingName = "tab_conf";
dgStyle.ColumnHeadersVisible = true;
dgStyle.HeaderBackColor = Color.LightGreen;
dgStyle.BackColor = Color.LightPink; DataGridColumnStyle dgCol1 = new DataGridTextBoxColumn();
dgCol1.MappingName = "tab_style";
dgCol1.HeaderText = "表类型";
dgStyle.GridColumnStyles.Add(dgCol1); DataGridColumnStyle dgCol2 = new DataGridTextBoxColumn();
dgCol2.MappingName = "tab_style_no";
dgCol2.HeaderText = "序号";
dgStyle.GridColumnStyles.Add(dgCol2); DataGridColumnStyle dgCol3 = new DataGridTextBoxColumn();
dgCol3.MappingName = "field_name";
dgCol3.HeaderText = "字段名";
dgStyle.GridColumnStyles.Add(dgCol3); DataGridColumnStyle dgCol4 = new DataGridTextBoxColumn();
dgCol4.MappingName = "field_type";
dgCol4.HeaderText = "数据类型";
dgStyle.GridColumnStyles.Add(dgCol4);

dgPoundConf.TableStyles.Clear();
dgPoundConf.TableStyles.Add(dgStyle);
                            dgPoundConf.SetDataBinding(dst,"");
为何无法修改datagrid中字段的标题名称??

解决方案 »

  1.   

    dataGrid1.TableStyles.Clear();
    dataGrid1.TableStyles.Add(....);
      

  2.   

    dgStyle.MappingName = "tab_conf";
    是否和你dst中对应的Tablename名称相同?
      

  3.   

    to 难得糊涂:
    dataGrid1.TableStyles.Clear();
    dataGrid1.TableStyles.Add(....);
    这两句话有啊
    dgPoundConf.TableStyles.Clear();
    dgPoundConf.TableStyles.Add(dgStyle);
    不知道为何??
    to 小人物:
    表名也是对的呀!!!
      

  4.   

    应该还是表名问题吧,你是用什么来填充dataset的,如果在填充的时候没有指定表名那么默认表名就是"Table",修改dgStyle.MappingName = "Table"试试.
      

  5.   

    dataGrid1.TableStyles.Clear();
    dataGrid1.TableStyles.Add(....);
    up
      

  6.   

    在ItemCreate中指定标题就可以了
      

  7.   

    连接什么的就不多说了
    DataSet dst;
    SqlDataAdapter adp = new SqlDataAdapter("select * from table",con);
    adp.Fill(dst);//这种是用的默认表名
    adp.Fill(dst,"tab_conf");//这种是指定表名