WPF DataGrid columns fun

We need to solve the following issue:

  • a DataTable is used as datasource
  • a new column must be inserted in the data table, with type bool, allowing the user to mark a row as “header row”
  • a “header row” is displayed with a different style
  • the user can check and uncheck any row; the code must ensure at most one row is marked as “header row” at a certain moment

The last issue I’ve run into: the DataTable object is not observable and the header style is not applied when the user checks a row.

I’ve implemented an observable collection over the DataTable, however I cannot use the AutoGenerateColumns property: instead of generating columns, the DataGrid generates only one column of type Collection.

Links I’ve studied so far:

http://dotnetpattern.com/wpf-datagrid-auto-generate-columns

Bindable DataGrid Columns

http://www.codeproject.com/Tips/676530/How-to-Add-Columns-to-a-DataGri

http://stackoverflow.com/questions/320089/how-do-i-bind-a-wpf-datagrid-to-a-variable-number-of-columns

http://www.reimers.dk/jacob-reimers-blog/auto-generating-datagrid-columns-from-dynamicobjects : this one may be the most important: use a PropertyDescriptor to describe the properties you want to be used when generating the columns.

May need to implement ICustomTypeDescriptor as well.

http://paulstovell.com/blog/dynamic-datagrid

Another option (probably the best one – long live Boggie!): use a RowHeaderTemplate!

http://xamlnative.com/

How to add columns programmatically (with a behavior): http://stackoverflow.com/questions/320089/how-do-i-bind-a-wpf-datagrid-to-a-variable-number-of-columns

Styling cheat sheet: https://blogs.msdn.microsoft.com/jaimer/2009/01/20/styling-microsofts-wpf-datagrid/

 

 

 

 

 

 

Finally Gold!

Our company has finally become Microsoft Gold Partner (Application Development Competency). I’m so proud of the people that did their best to make this happen (and of course I was one of them)!