Get column index by Column header in WPF DataGrid

后端 未结 2 789
半阙折子戏
半阙折子戏 2021-01-12 10:26

How to get the Column index or Column.DisplayIndex from its Column Header in WPF DataGrid?

I know th

2条回答
  •  孤城傲影
    2021-01-12 10:53

    Look like "paul" have an small error. Here is my code:

    var index = dataGrid.Columns.Single(c => c.Header.ToString() == "HeaderName").DisplayIndex;
    

提交回复
热议问题