I prefer to bind my grids to collections because it gives me strongly named properties and Intellisense lets me know when I have fat-fingered a property name. But when editing data we need to track row state so we can surgically persist the data back to the database. It's hard to improve on the DataRow.RowState so I'm not even going to try. But how do we handle child rows?
I like the Infragistics solution - it's elegant. Define a data relationship and reference that in the FieldLayout. Like this...
<igDP:XamDataGrid DataSource="{Binding DS.Tables[Vendors]}">
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Description="Vendors" Key="Vendors">
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Vendor Number" Name="VendorNumber" Width="80"/>
<igDP:TextField Label="Detail" Name="VendorDetailNumber" Width="40"/>
<igDP:TextField Label="Vendor Name" Name="Name" Width="200"/>
<igDP:Field Label="" Name="Vendor_Contacts"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
<igDP:FieldLayout Description="Contacts" ParentFieldLayoutKey="Vendors" ParentFieldName="Vendor_Contacts">
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Name" Name="Name" Width="150"/>
<igDP:TextField Label="Title" Name="Title" Width="100"/>
<igDP:TextField Label="Phone" Name="Phone1"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
See how the DataRelation is named in the Parent Field definition and referenced in the child's FieldLayout. This is very similar to how we bind child bands when binding to collections. the result is exactly what you would expect.
No comments:
Post a Comment