I have a datagrid in my WPF application and i am binding an Ienumerable collection to the itemsource of the datagrid.
I need to add a handler for AutoGenerated columns in DataGrid after binding it.
But i can’t.
this.dataGrid1.ItemsSource = ineumerable_collection;
dataGrid1.AutoGeneratedColumns += new EventHandler(dataGrid1_AutoGeneratedColumns);//Not working
I have set Autogeneratecolumns as True in my XAML. But when i run my application it is not invoking the event handler dataGrid1_AutoGeneratedColumns.
Thanks in advance if u could solve my problem!
The problem is that you’re attaching the event handler after you’ve changed the
ItemsSource, which means the columns get generated before your handler is attached. Just switch the order of the two statements.