Background:
I have a ListView
/GridView
with several columns. In some situations, only some of the columns are shown. Since there is no Visible
property for GridViewColumns
in WPF, I set the width of the columns I want to hide to zero. Visually, this achieves the desired effect (and I actually modified the ControlTemplate
for the GridViewColumnHeader
so that it's impossible for the user to accidentally expand any hidden columns).
Problem:
The problem is that the bindings for the hidden columns are still in play, and they are trying to look up data that doesn't exist. In this case, it causes an IndexOutOfRangeException
since it's trying to look up a column name that doesn't exist on the DataTable
that it is bound to.
Question:
How can I temporarily disable or detach the binding for columns that are hidden? Or please suggest a better solution if you have one.
Thanks!