Question

I have created a WPF tooklit datagrid in C# and the ItemsSource is set in the XAML. The columns are automatically generated.

I am trying to do a datagrid that uses an ObservableCollection, pretty much like what is on this website.

At the bottom you will find a sample that you can download (here is the link)

My problem is that I'm trying to change certain properties of a specific column (example: Datagrid.Columns[index].Property) but this does not seem to work since the the column count is always equal to 0. Therefore, I cannot change the properties by using the index that I want to use because there seems to be nothing in the Columns collection. Yet at runtime there are columns that are displayed.

So, how can it be possible that column count is equal to 0?

and

How can I change the properties of a specific column in my situation?

Was it helpful?

Solution

I have finally found how! The reason that the column count equals 0 is because the columns are not yet generated. In order to change the properties I have to use the AutoGeneratedColumns event and change the properties in there.

OTHER TIPS

According to several forum experiences, columns aren't accessible via the Columns property if they are autogenerated. I don't know why this is so, but it has been seen before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top