Version

Cell Merging (xamDataGrid)

Topic Overview

Purpose

This topic gives an overview of the xamDataGrid control’s grouping functionality allowing users to group data into more readable and navigable arrangements.

The DataPresenter controls have several modes and properties for this feature, which you can configure via the FieldSettings object.

Required background

The following topic is a prerequisite to understanding this topic:

Topic Purpose

This topic introduces the xamDataGrid control and various elements, on which control is composed.

Grouping Overview

A DataPresenter control such as a XamDataGrid control may opt-in and detect when adjacent sibling DataRecords for a specific Field contains the same value. While the cells are not in edit mode, the value displays across the DataRecords, and is represented as by a MergedCellPresenter.

xamDataGrid MergeCells 01.png

Main Settings Summary

Main settings summary chart

The xamDataGrid is highly user configurable using these settings.

Settings Description

FieldSettings class property that specifies if and how cell merging is performed.

This property’s default setting is Never.

FieldSettings class property that provides a custom evaluator to determine if cells for 2 adjacent records can be merged.

This property’s default setting is Never.

FieldSettings class property that determines which cells can be merged based on either the cell’s value or its display text.

This property’s default setting is Never.

MergedCellMode

You can set this MergedCellMode property to a enum of type MergedCellMode to specify if and how cell merging is performed.

Note
Note

For the cell merging to work the MergedCellMode property must be set to either Always, Default, Never, or OnlyWhenSorted.

Regardless of the value of this property, cells can only be merged across sibling DataRecords in grid view or tree view and only if the cells span the height of the record in vertical orientation or the width of the record in horizontal orienation. Also note that the tree field in tree view does not support cell merging at all.

MergedCellEvaluator

This property can be set to a custom implementation of the IMergedCellEvaluator interface. The interface is used to specify custom logic for determining which cells get merged.

MergedCellEvaluationCriteria

You can set this MergedCellEvaluationCriteria property to a enum of type MergedCellEvaluationCriteria to determine which cells can be merged based on either the cell’s value or its display text.

Note
Note

For the cell merging to work the MergedCellEvaluationCriteria property must be set to either Converted, Default, DisplayText, EditAsType, or RawValue.

If a IMergedCellEvaluator is specified then this property is ignored.

Code Example

The following example code demonstrates how to merge cells for all fields.

In XAML:

<igDP:XamDataPresenter Name="xamDataPresenter1" BindToSampleData="True">
    <igDP:XamDataGrid.FieldSettings>
        <igDP:FieldSettings MergedCellMode="Always" >
        </igDP:FieldSettings>
    </igDP:XamDataGrid.FieldSettings>
</igDP:XamDataPresenter>

In C#:

using Infragistics.Windows.DataPresenter;
...
this.xamDataPresenter1.FieldSettings.MergedCellMode = MergedCellMode.Always;
...

In Visual Basic:

Imports Infragistics.Windows.DataPresenter
...
Me.xamDataPresenter1.FieldSettings.MergedCellMode = MergedCellMode.Always
...

The following screenshot is an example of using the code above.

xamDataGrid MergeCells 02.png

The following example code demonstrates how to merge cells for a specific field.

In XAML:

<igDP:XamDataGrid DataSource="{Binding}" >
    <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout Key="layout1">
            <igDP:FieldLayout.Fields>
                <igDP:Field x:Name="department">
                    <igDP:Field.Settings>
                        <igDP:FieldSettings MergedCellMode="Always" >
                        </igDP:FieldSettings>
                    </igDP:Field>
            </igDP:FieldLayout.Fields>
        </igDP:FieldLayout>
    </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

In C#:

using Infragistics.Windows.DataPresenter;
...
this.xamDataPresenter1.FieldLayouts["layout1"].Fields["department"].Settings.MergedCellMode = Infragistics.Windows.DataPresenter.MergedCellMode.Always;
...

In Visual Basic:

Imports Infragistics.Windows.DataPresenter
...
Me.xamDataPresenter1.FieldLayouts("layout1").Fields("department").Settings.MergedCellMode = Infragistics.Windows.DataPresenter.MergedCellMode.Always
...