简体   繁体   English

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

[英]How to change the header of a DataGrid column in code behind?

How can I change the header of a DataGrid column in code behind? 如何在后面的代码中更改DataGrid列的标题?

Example: 例:

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

I would use DisplayName of your binding item class as below 我将使用如下所示的绑定项目类的DisplayName

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

使用DataGrid.Columns:

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

您可以在Page_Load更改DataGrid的标题

dataGrid.HeaderRow.Cells[0].Text = "Any thing that you want to Enter";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM