WPF DataGrid default column types


I'm using a DataGrid to display 2 possible types of DataRow in a DataTable. One type has the column Parent = NULL and the other has Parent set to another DataRow in the same DataTable. The list of column in the DataTable is always different, so explicitly describing each column is not possible.

I want to display a UserControl in every cell of the Parent = DataRow rows, and default Text / Check boxes for the Parent = NULL rows. My first strategy is to try and set the default Column type for all automatically generated columns to be a DataGridTemplateColumn, regardless of datatype, so that I can use styles to then use either my UserControl or CheckBox or TextBox where required. How can I do this?

More importantly, though, is there a better strategy than this?

Cheers, Dave
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


this is kind of a 30,000ft overview so i'm not sure i understand your situation exactly, but is it possible to use data templates rather than user controls and use the type binding to resolve which UI to use? so you create a data temlpate for the data type displayed?

Otherwise i wonder if you'd be able to set the cell control template within a style where you can apply a trigger to the Parent property? i think this allow you to have your two cell templates...

i could be barking up the wrong tree(s) here, these were just my thoughts...


AJS_DeveloperAuthor Commented:
Thanks for your suggestion mikebirt. I've now abandoned the DataGrid in favour of a ListView which I've found meets my needs a littler better.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.