Search code examples
c#wpflistviewgridviewcolumncolumnheader

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?


Solution

  • 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).