I'm trying to add a context menu to a ListView (using GridView) to toggle column visibility. It's a simple menu - it just has a list of all the available columns, and if the column name is checked, that column should be visible.
My ListView is displayed with a GridView. The GridViewColumnHeader for each column has a Name property and Header property that match with a ContextMenu MenuItem with the same Name and Header values. My problem is that I can't figure out how to select a GridViewColumn by its GridViewColumnHeader's name without iterating through all the columns.
I can select a column by index, but that won't work since the column index changes if the columns are reordered by the user.
Is there a way to select a column by header data? I'm thinking something like this:
MenuItem m = e.Source as MenuItem;
GridView gv = (GridView)list.View;
GridViewColumn gvc = gv.Columns[m.Name];
//code to make width 0 or Auto goes here...