通过 WPF DataGrid 中的列标题获取列索引 [英] Get column index by Column header in WPF DataGrid

查看:25
本文介绍了通过 WPF DataGrid 中的列标题获取列索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 WPF 中的 Column Header 获取 Column 索引或 Column.DisplayIndex数据网格?

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

我知道Column Header,想得到column index.

推荐答案

你可以使用 DisplayIndex(请注意,如果重新使用列,这会改变)

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

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

已感谢@AnHX 的建议

edited: thanks for suggestion from @AnHX

这篇关于通过 WPF DataGrid 中的列标题获取列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆