3

I'm binding a datagrid to a DataView. I would like to hide the ID column when the data is displayed. The ID column needs to exist in the data as it is used in another part of my code.

The ID column is always the first (index 0) column.

Am I right in thinking that the DataContextChanged event doesn't guarantee that all columns have been refreshed?

How can I ensure that binding has finished before hiding the column? Ideally, I would like to hide it by its column name.

EDIT: Forgot to say that I can't specify the columns in XAML, as they are generated from dynamic SQL.

Jay
  • 2,077
  • 5
  • 24
  • 39

1 Answers1

9

I figured it out.

In the AutoGeneratingColumn event, I'm checking the DataGridAutoGeneratingColumnEventArgs header value and canceling the operation if it matches the column header.

Private void dataGrid_AutoGeneratingColumn(object sender,     DataGridAutoGeneratingColumnEventArgs e)
        {
            if (e.Column.Header.ToString() == "ID")  
            {
                e.Cancel = true;
            }
        }
Jay
  • 2,077
  • 5
  • 24
  • 39