如何在代码后面更改DataGrid列的标题?

时间:2013-12-19 11:30:47

标签: c# wpf datagrid

如何在代码后面更改DataGrid列的标题?

示例:

var dataGrid = new DataGrid();            
dataGrid.ItemsSource = someRecords;
// ... now I want to change a column header ...

3 个答案:

答案 0 :(得分:3)

我会使用您的绑定项目类的DisplayName,如下所示

public class YourItemClass
{
    [DisplayName("Column Name")]
    public string SomeProperty{ get; set; }
}

答案 1 :(得分:2)

使用DataGrid.Columns:

   dataGrid.Columns[0].Header = "New Header for column 0";

答案 2 :(得分:1)

您可以在Page_Load

中更改DataGrid的标头
dataGrid.HeaderRow.Cells[0].Text = "Any thing that you want to Enter";