Get column index by Column header in WPF DataGrid

允我心安 提交于 2019-12-30 08:33:15

问题


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.


回答1:


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




回答2:


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

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


来源:https://stackoverflow.com/questions/13071346/get-column-index-by-column-header-in-wpf-datagrid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!