Hello,
I have seen several requests for information regarding how to programmatically set a FieldLayout and how to define a hierarchy between FieldLayouts. I figured I would share the information from a recent support case regarding this very issue:In order to define a FieldLayout programmatically or through xaml, the most important thing is to set the Name property on your Fields. The Name property is what identifies which field in your DataSource maps to which field in your FieldLayout. The value you use depends on the object you are binding to. For instance, if you are using a generic collection of custom objects, the Name property would be set to each property in your custom object. For a DataSet, the Name property would be set to your Column names in the DataTable.
The grid then uses it's own logic to determine which FieldLayout should be applied to which collection of items based off of the schema of the Fields. In order to create a hierarchy, you would define a field in your parent FieldLayout. The value of the field's Name to properly show the hierarchy would depend on the type of DataSource. For instance, if you are binding to a list of custom objects, the Name of the field should be named after the property on your object which returns the collection of child objects. If you are using a DataSet, the Name of the field would be set as the name of the DataRelation that connects the two DataTables.
Please see the simple sample that I attached which shows how to programmatically define FieldLayouts for binding with a DataTable. One key thing to note is that the FieldLayouts should be set to the grid before the DataSource so that the data is applied correctly to the layouts.