Hi,
I have a collection of objects, each of which has a single child which for this example, we can call Order and OrderStatus. If I bind my collection to my DataGrid, I can create columns for the primitive fields on the parent and I can create a column with the child's type but I cannot seem to figure out how to create columns with data from the child. The relevant code is below.
<!-- This code works and correctly displays the Id in the only column in the grid. -->
<igDP:XamDataGrid Name="Orders" DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name = "Id" Label = "Id" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
<!-- This code does not work though similar code in other parts of my application does. In fact, adding the bolded line causes the grid to not display any data at all -->
<igDP:XamDataGrid Name="customerSpecialOrders" DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name = "Id" Label = "Id" /> <igDP:Field Name="{Binding OrderStatus.Description}" Label="Status" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Undoubtedly, this has to do with me not completely understanding WPF and/or the xamDataGrid yet but since it works in another part of my application using other WPF controls, I'm at a loss as to why it doesn't work with the xamDataGrid. Any help would be greatly appreciated.
Brett
I need this anwser too.
You need to create two layouts, something along these lines.
<igDP:XamDataGrid Name="Orders" DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout x:Uid="Parent"> <igDP:FieldLayout.Fields> <igDP:Field Name = "Id" Label = "Id" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> <igDP:FieldLayout x:Uid="Child"> <igDP:FieldLayout.Fields> <igDP:Field Name = "Description" Label = "Status" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Hope this helps.
I tried that but it didn't seem to work. I don't see anything in the documentation that would indicate that a second FieldLayout section would be able to interpret the Child class data so I'm curious how that would work. For what it's worth, I've posted my code below.
<ui:IspPage x:Class="ISP.Console.UI.CustomerSpecialOrderPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igWindows="http://infragistics.com/Windows" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:igEditors="http://infragistics.com/Editors" xmlns:ui="clr-namespace:ISP.Console.UI" Title="Customer Special Orders"> <Grid> <igDP:XamDataGrid Name="customerSpecialOrders" DataSource="{Binding}" > <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" HighlightAlternateRecords="True"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout x:Uid="MyParentClass"> <igDP:FieldLayout.Fields> <igDP:Field Name="Id" Label="Order#" /> <igDP:Field Name="CustomerName" Label="Customer Name" /> <igDP:Field Name="CustomerPhone" Label="Phone#" /> <igDP:Field Name="DateNeeded" Label="Date Needed" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> <igDP:FieldLayout x:Uid="MyChildClass"> <igDP:FieldLayout.Fields> <igDP:Field Name="OrderStatus.Description" Label="Status" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> <TextBlock Text="{Binding OrderStatus.Description}" /> </Grid></ui:IspPage>
My parent class displays in the gird fine but I can't seem to get any data off the child classes. For comparison's sake, I added the TextBlock at the end to test the binding and that TextBlock has the correct data in it.
That did the trick, I knew it would be painfully easy once I knew the steps. Thanks for the help.