Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to get Data grid column header

$
0
0

Hi Experts,

Im binding a colletion to a data grid and the columns are auto generated, so by default column header would be the property name. So i have added two meta data attributes to binding collection properties (which will have the actual header name and column display index)

[HeaderName("First Name"), ColumnIndex("0")]
 public string FirstName { get; set; }

Using reflection i will be accessing property meta data and get the header and and index and want to customize the grid. Is there any way to get the data grid column name within any of the following events ?

DataGrid_AutoGeneratedColumns(object sender, EventArgs e)
DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)

I was able to access the columns using index but i want to access using header name,

private void DataGrid_AutoGeneratedColumns(object sender, EventArgs e)
        {
            var grid = (DataGrid)sender;
            grid.Columns[0].DisplayIndex = 2;
}




Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>