How to get a Column or Column.DisplayIndex from its Column Header in a WPF DataGrid ?
Column
Column.DisplayIndex
Column Header
WPF
DataGrid
I know Column Header , I want to get column index .
column index
you can use DisplayIndex (remember that this will change when using columns)
DisplayIndex
var index = dataGrid.Columns.Single(c => c.Header.ToString() == "HeaderName").DisplayIndex;
edited: thanks for the suggestion from @AnHX
It seems that "paul" has a little mistake. Here is my code: