I have an object that I want to bind to the data grid to include child records. If I set AutoGenerateFields = true I get the expected child rows coming from the "Details" collection on the "TopLevelObject". However if i set AutoGenerateFields=false no child rows appear for the "Details". After searching the online documentation I found this page which I was unable to follow for manual binding: http://help.infragistics.com/Help/NetAdvantage/WPF/2010.1/CLR3.5/html/xamDataPresenter_Define_a_Field_Layout.html
Below is some simple C# code from my testing app. I'm probably missing something very simple in order to make the connection between the ParentLayout and the Details layout. Any light someone could shine on this would be greatly appreciated.
public Window1(){ InitializeComponent();
DetailObject detailObject1 = new DetailObject() { Detail1 = "details 1a", Detail2 = "details 2a" }; DetailObject detailObject2 = new DetailObject() { Detail1 = "details 1b", Detail2 = "details 2b" };
Collection<DetailObject> detailObjectCollection = new Collection<DetailObject>(); detailObjectCollection.Add(detailObject1); detailObjectCollection.Add(detailObject2);
TopLevelObject topLevelObject1 = new TopLevelObject() { Name = "Name1", Description = "Desc1", Details = detailObjectCollection }; TopLevelObject topLevelObject2 = new TopLevelObject() { Name = "Name2", Description = "Desc2", Details = detailObjectCollection }; TopLevelObject topLevelObject3 = new TopLevelObject() { Name = "Name3", Description = "Desc3" };
Collection<TopLevelObject> topLevelObjectCollection = new Collection<TopLevelObject>(); topLevelObjectCollection.Add(topLevelObject1); topLevelObjectCollection.Add(topLevelObject2); topLevelObjectCollection.Add(topLevelObject3);
myGrid.DataSource = topLevelObjectCollection;}
public class TopLevelObject{ public TopLevelObject() { } public string Name { get; set; } public string Description { get; set; } public string NotToDisplay { get; set; } public Collection<DetailObject> Details { get; set; }}
public class DetailObject{ public DetailObject() { } public string Detail1 { get; set; } public string Detail2 { get; set; } public string NotToDisplay { get; set; }}
<igDP:XamDataGrid x:Name="myGrid"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout Key="ParentLayout"> <igDP:FieldLayout.FieldSettings> <igDP:FieldSettings ExpandableFieldRecordHeaderDisplayMode="NeverDisplayHeader"/> </igDP:FieldLayout.FieldSettings> <igDP:UnboundField x:Name="nameField" Label="Name" BindingPath=".Name"/> <igDP:UnboundField x:Name="descriptionField" Label="Description" BindingPath=".Description" /> <igDP:UnboundField x:Name="Details" Label="Details" BindingPath=".Details"/> </igDP:FieldLayout> <igDP:FieldLayout ParentFieldLayoutKey="ParentLayout" Key="Details"> <igDP:UnboundField x:Name="detail1Field" Label="Detail 1" BindingPath=".Detail1"/> <igDP:UnboundField x:Name="detail2Field" Label="Detail 2" BindingPath=".Detail2"/> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Thank you for posting the answer. You really helped.
I was able to hook in the child field layout by changing the UnboundField "Details" to a Field with Name="Details". I also had to change the child FieldLayout Key="DetailObject".
Voila, the child rows displayed.