[英]How to change the header of a DataGrid column in code behind?
如何在后面的代碼中更改DataGrid列的標題?
例:
var dataGrid = new DataGrid();
dataGrid.ItemsSource = someRecords;
// ... now I want to change a column header ...
我將使用如下所示的綁定項目類的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.