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.

1 Answer 1

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;
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.