Limbo Exile
Limbo Exile

Reputation: 1351

How to get a GridViewColumn by its header's name in WPF?

To get a column of a ListView in WPF we can do

((GridView) someListView.View).Columns[index] 

But how to get a GridViewColumn knowing only the name of its header?

Upvotes: 0

Views: 1925

Answers (1)

MDoobie
MDoobie

Reputation: 282

You should try this: ((GridView) _lvContacts.View).Columns.FirstOrDefault(x => (string) x.Header == "Name"); Of course, you have to be sure the column's header is only a string (just like in your sample code).

Upvotes: 1

Related Questions