【发布时间】:2009-05-22 14:50:37
【问题描述】:
我在 WinForm 应用程序中使用 DataGridView 来显示数据表。除了 DataColumn 的 Caption 属性外,一切正常。我尝试设置 Caption 属性,但似乎 DataGridView 使用 DataColumn 的名称作为标题而不是 Caption 属性的值?
对此有谷歌,似乎这个标题属性是故意禁用的。
我的 WinForm 应用程序是本地化的,我需要用中文显示标题。有谁知道我该怎么做?
这是我设置数据表的代码
// Create a new DataTable.
DataTable table = new DataTable("Payments");
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
column.ReadOnly = true;
column.Unique = true;
column.Caption = LocalizedCaption.get("id") //LocalizedCaption is my library to retrieve the chinese caption
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);
// Create three new DataRow objects and add them to the DataTable
for (int i = 0; i <= 2; i++)
{
row = table.NewRow();
row["id"] = i;
table.Rows.Add(row);
}
//assign the DataTable as the datasource for a DataGridView
dataGridView1.DataSource = table;
【问题讨论】:
标签: c# winforms datagridview internationalization