WPF DataGrid and Hiding Columns

Looking for advice here 🙂 I find that in the WPF/Silverlight DataGrids there’s this option which is really useful;


but I generally don’t want either true or false. What I seem to want is;

“Autogenerate all of them but I don’t want to display columns A,B,C”

and I’m not sure how I do that. I ended up deriving my own DataGrid just to try and make that work as in;

  public class HiddenColumn
    public HiddenColumn()
    public string Name { get; set; }
  class HideableDataGrid : DataGrid
    public HideableDataGrid()
      HiddenColumns = new List<HiddenColumn>();
      this.AutoGeneratingColumn += OnGeneratingColumn;

    void OnGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
      if (HiddenColumns != null)
        e.Cancel = HiddenColumns.Exists(hc => string.Compare(e.PropertyName, hc.Name, true) == 0);
    public List<HiddenColumn> HiddenColumns { get; set; }

and then use that as in;

      Style="{StaticResource myStyle}"
      DataContext="{Binding ElementName=customersGrid,Path=SelectedValue.Orders}"

but this can’t be the right thing to do here? ( + the naming I’ve given the derived class is horrible ).