WPF Datagrids with outer and inner object properties making columns in a row

I've got an object which contains some properties, but also other objects.
As an example:

Class OuterObject{ Public InnerObj1 InnerObj1{ get; set; } Public InnerObj2 InnerObj1{ get; set; } Public InnerObj3 InnerObj1{ get; set; } Public string OuterObjProperty{ get; set; } } 

When I make a list of OuterObjects for the ItemsSource the datagrid contains 1 column per InnerObj with the contents something like "OuterObject.InnerObj".
It doesn't add the inner object's properties to the datagrid row. Is there a way to do this? Or do I need to make a new object containing all the properties I want available in the datagrid from the outer and inner object(s)?
There are around 60 inner and outer object properties total and I want the user to be able to set which columns are visible out of that total. I'm having trouble figuring out the proper way to do this.. because making a new object with duplicate data seems both tedious to do on my part and a waste of resources.. Also is there a way to set the chosen columns without using a big else if or switch block to check if each individual column should be displayed or not?

TL;DR Take the OuterObject, and put user picked properties from the outer and inner objects into datagrid.

by pyrojoe via /r/csharp

Leave a Reply