DataGrid更改列标题问题

supergoalcn 2004-01-19 02:07:14
//为dgInputBuffer设置数据库
customerTable = new DataTable( "Customers" );
//添加字段
customerTable.Columns.Add( "ISBN", typeof(string) );
customerTable.Columns.Add( "Name", typeof(string) );
customerTable.Columns.Add( "Publisher", typeof(string) );
customerTable.Columns.Add( "Author", typeof(string) );
customerTable.Columns.Add( "Index1", typeof(string) );
customerTable.Columns.Add( "Index2", typeof(string) );
customerTable.Columns.Add( "Price", typeof(decimal) );
customerTable.Columns.Add( "Number", typeof(int) );
//设置关键字
customerTable.Columns[ "ISBN" ].Unique = true;
customerTable.PrimaryKey = new DataColumn[] { customerTable.Columns["ISBN"] };
this.dgInputBuffer.DataSource = new DataView(this.customerTable);

之后,dgInputBuffer(DataGrid)每一列的标题都是英文的,但我想要把它们都改成相对的中文,该如何做?
...全文
31 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
supergoalcn 2004-01-19
  • 打赏
  • 举报
回复
稍有点出入,但给分的。

DataGridTableStyle ts = new DataGridTableStyle();

this.dgInputBuffer.TableStyles.Clear();
ts.MappingName = "Customers";

DataGridTextBoxColumn col1 = new DataGridTextBoxColumn();
col1.HeaderText = "ISBN";
col1.MappingName = "ISBN";

DataGridTextBoxColumn col2 = new DataGridTextBoxColumn();
col2.HeaderText = "书名";
col2.MappingName = "Name";

DataGridTextBoxColumn col3 = new DataGridTextBoxColumn();
col3.HeaderText = "出版社";
col3.MappingName = "Publisher";

DataGridTextBoxColumn col4 = new DataGridTextBoxColumn();
col4.HeaderText = "作者";
col4.MappingName = "Author";

DataGridTextBoxColumn col5 = new DataGridTextBoxColumn();
col5.HeaderText = "一级编号";
col5.MappingName = "Index1";

DataGridTextBoxColumn col6 = new DataGridTextBoxColumn();
col6.HeaderText = "二级编号";
col6.MappingName = "Index2";

DataGridTextBoxColumn col7 = new DataGridTextBoxColumn();
col7.HeaderText = "价格";
col7.MappingName = "Price";

DataGridTextBoxColumn col8 = new DataGridTextBoxColumn();
col8.HeaderText = "入库数量";
col8.MappingName = "Number";

ts.GridColumnStyles.AddRange(new DataGridColumnStyle[]{col1, col2, col3, col4, col5, col6, col7, col8});
this.dgInputBuffer.TableStyles.Add(ts);

this.dgInputBuffer.SetDataBinding(this.customerTable, "");

this.dgInputBuffer.DataSource = new DataView(this.customerTable);
巍巍清风 2004-01-19
  • 打赏
  • 举报
回复
this.dgInputBuffer.TableStyles.Clear();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "Customers";

DataGridTextBoxColumn col1 = new DataGridTextBox();
col1.HeaderText = "ISBN";
col1.MappingName = "ISBN";

DataGridTextBoxColumn col2 = new DataGridTextBox();
col2.HeaderText = "书名";
col2.MappingName = "Name";

...

ts.GridColumnStyles.AddRange(new DataGridColumnStyle[]{col1, col2, ...});

this.dgInputBuffer.TableStyles.Add(ts);

this.dgInputBuffer.SetDataBinding(this.customerTable, "");
supergoalcn 2004-01-19
  • 打赏
  • 举报
回复
To shenanigan(宝宝):
那我该怎么设置中文名呢?

To reformer((问自己最不懂的问题)):
我不能改成中文,因为代码中很多地方都得改到了。
reformer 2004-01-19
  • 打赏
  • 举报
回复
你直接把数据源就是DataTable的列名改为中文的不救可以了吗?
shenanigan 2004-01-19
  • 打赏
  • 举报
回复
把這個屬性脩改城這個AutoGenerateColumns="False"

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧