I understand that if you bind a collection whose members include another collection you will by default get hierarchical field layouts. But is there a way to join the two field layouts so that the properties of the parent model are displayed in line, for n rows, where n is the number of child data models? Like an inner join of two tables where the shared value appears in a one->many pattern. Thanks.
Hello,
I assume you would like to hide all parent rows, and include the information from the parent row in every child row. If this is the case, the best way would be to create a method that returns a new collection of objects with all properties you would like to be displayed and bind the grid to it.
Hiding parent rows will always hide the child rows as well. The only workaround would be to set the height of the parent row to 0 and make the borders transparent, but that will not remove the indentation between the rows and make it feel unnatural and unaesthetic.
Should you have any further questions, please let me know.
Sincerely,Tihomir TonevAssociate Software Developer
So i definitely want to avoid workarounds that tweak the appearance of rows, feels a bit hackish.
Is there a sample that maybe indicates a reasonable and efficient pattern for the method you're suggesting?
Don't worry about it if there's no existing sample or example you can point me to, I only want to know if there's a recommended best practice for this use case.
My thought right now: I'm sure I could extend the child class to include fields from the parent class, and have parent produce a collection of child+parent type objects, but I'm curious if there are any recommended solutions that would let me avoid having redundant object properties in a new class.
Thanks.
As we do not have an implemented method to convert Hierarchical data into flat, it will be all custom implementation, and the complexity of the method would be based on how generic the method is going to be, and will it check for nested collections until it hits the bottom.
In case you know all properties of the classes, and you are not going after generic methods, you can do something simple as this.
var allChildren = new ObservableCollection<object>(); foreach (var parent in parentCollection) { foreach(var child in parent.Children) { allChildren.Add(new { parent.property1, parent.property2, child.property1, child.property2, child.property3 }); } }
xamDataGrid1.DataSource = allChildren;
If you need further help, please let me know.
Sincerely,Tihomir TonevInfragistics