Version

Assigning a FieldLayout

A FieldLayout defines the Fields (columns) contained in a particular DataRecord. When a DataRecord is created, the FieldLayouts collection is searched for an existing FieldLayout whose Fields match the DataItem's properties. If a FieldLayout is found, it is associated with the DataRecord; if it is not found, a new FieldLayout is created. When a new FieldLayout is created, the FieldLayoutInitializing and FieldLayoutInitialized events are raised.

If the new FieldLayout’s AutoGenerateFieldsResolved property returns True, the Fields collection is automatically populated with a Field for every public property on the data item.

Note
Note

There are some data types where a single field named "Value" is generated instead. These include primitive types such as plus, string, decimal, DateTime, DayOfWeek, Color and any type derived from Visual or Animatable.

The auto-generation of Fields is done between the FieldLayoutInitializing and FieldLayoutInitialized events.

Note
Note

Auto-generation of fields should not be confused with the "AutoArrange" feature which involves creating an arrangement (layout) for CellValuePresenters within a DataRecordPresenter. The 'AutoArrange' feature is described below under the heading "Arranging cells within the record".

The automatic generation of Fields combined with the automatic generation and view-dependent arrangement of CellValuePresenters (described below), provides a great "no-touch" development solution for binding to complex data sources and displaying a robust UI for displaying/editing data, all with minimal developer effort.

The AssigningFieldLayoutToItem event is then raised to allow a different FieldLayout to be assigned to the DataRecord. Then, finally, the InitializeRecord event is raised.

Accessing Properties Specific to a Derived Record Type

The InitializeRecord event is raised for DataRecords, GroupByRecords and ExpandableFieldRecords so the InitializeRecordEventArgs exposes a property that returns the base Record class. Therefore, to access properties that are specific to one of the derived Record types, you need to cast to the appropriate type, as shown in the example code below.

private void OnInitializeRecord(object sender, InitializeRecordEventArgs e)
{
        DataRecord dr = e.Record as DataRecord;
        if (dr != null)
        {
                Cell cell = dr.Cells["CustomerName"];
        }
}

Manually Adding Fields

The example XAML below shows how to manually add fields instead of using the AutoGenerateFields feature. It also shows how to add additional unbound fields:

<igDP:XamDataGrid>
        <igDP:XamDataGrid.FieldLayoutSettings>
                <igDP:FieldLayoutSettings
                  AutoGenerateFields="False"/>
        </igDP:XamDataGrid.FieldLayoutSettings>
        <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout>
                        <igDP:FieldLayout.Fields>
                                <igDP:Field Name="CustomerName" Label="Customer Name"/>
                                <igDP:Field Name="Address"/>
                                <igDP:Field Name="City"/>
                                <igDP:Field Name="MyExtraDataColumn" BindingType="Unbound"
                                  DataType="{x:Type sys:Decimal}"/>
                        </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
        </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Note
Note

In the example XAML code above, if the AutoGenerateFields property was left to its default value of True, the xamDataPresenter™ will generate Fields for any additional public properties found on the DataRecord, and append them to the end of the collection. Note that since thefCustomerName field was manually defined as the first field, it will be considered the "Primary" field by default. The Primary field receives special handling when using the AutoArrange feature, as described in the Arranging Cells within the Record topic.