简体   繁体   中英

Get column index by Column header in WPF DataGrid

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

I know the Column Header , want to get column index .

you could use DisplayIndex (be aware this will change if columns are resorted)

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

edited: thanks for suggestion from @AnHX

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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