Version

Selection Overview

All Ultimate UI for WPF controls derived from the DataPresenterBase class have built-in support for selection of cells, records, and fields. There are three different selection modes available on the SelectionType enumeration:

  • no selection

  • selection of one object at a time

  • extended selection of multiple objects at a time (either programmatically, or by the user holding down the SHIFT or CTRL key as they select by clicking their mouse button).

different types of selection available in xamdatagrid

You can enable Cell selection by setting the SelectionTypeCell property to Single or Extended, or disable Cell selection by setting this property to None.

You can enable Record selection by setting the SelectionTypeRecord property to Single or Extended, or disable Record selection by setting this property to None.

Note
Note

While cell and record selection modes can be enabled simultaneously, the end user can select either cells or records at any one time. Selecting a different cell will clear any previously selected records, while selecting a different record will clear any previously selected cells.

You can enable Field selection by setting the SelectionTypeField property to Single or Extended, or disable Field selection by setting this property to None. Because the default behavior for clicking on the Field Label is to sort on the Field, you must also set the LabelClickAction to SelectField in order to enable the user to select a field by clicking on it.

The following XAML demonstrates how to set up multiple Field selection in a xamDataGrid™. The procedure for the other selectable object types will be similar in any control derived from the DataPresenterBase class. Remember, changing the LabelClickAction is only required to enable Field selection.

In XAML:

<igDP:XamDataGrid.FieldLayout>
    <!-- You would put your Fields here. -->
    <igDP:Field Name="Field1">
        <igDP:Field.Settings>
            <igDP:FieldSettings LabelClickAction="SelectField" />
        </igDP:Field.Settings>
    </igDP:Field>
</igDP:XamDataGrid.FieldLayout>
<igDP:XamDataGrid.FieldLayoutSettings>
    <igDP:FieldLayoutSettings SelectionTypeField="Extended" />
</igDP:XamDataGrid.FieldLayoutSettings>

If you require the AutogenerateFields to create your Fields dynamically, then you may prefer to enable Field selection programmatically. You can attach the following FieldLayoutInitialized event handler to your DataPresenterBase-derived control to accomplish this task.

In Visual Basic:

Sub OnFieldLayoutInitialized( ByVal sender As Object, ByVal e As FieldLayoutInitializedEventArgs)
        Dim f As Field
        Dim lo As FieldLayout = e.FieldLayout
        For Each f In lo.Fields
                f.Settings.LabelClickAction = LabelClickAction.SelectField
        Next
        lo.Settings.SelectionTypeField = SelectionType.Extended
End Sub

In C#:

void OnFieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e)
{
        FieldLayout lo = e.FieldLayout;
        foreach (Field f in lo.Fields)
        {
                f.Settings.LabelClickAction = LabelClickAction.SelectField;
        }
        lo.Settings.SelectionTypeField = SelectionType.Extended;
}

Every selectable item has an IsSelected property. In the Ultimate UI for WPF product, you will frequently use this property as a Condition for your Style Triggers to display selected items differently (for example, painted with a different background brush). This gives your users the visual feedback that they will expect regarding their selection.

datapresenterbase selection API

We will now describe the selection capabilities exposed by DataPresenterBase-derived controls. You can refer to the properties and events specified in the above image.

The selected item or items are always accessible to your application through the control’s SelectedItems property, which exposes strongly-typed collection properties for the Cells, Records, or Fields that are selected.

There is a distinction that you need to understand between the activated item, and any selected item or items. When a user clicks on a cell or record, that item will become activated. Activation will cause several activation events to fire on the record, followed by the cell (if a cell was activated). If selection has been enabled, then the active item will also be a selected item, unless you have canceled its selection event (see below).

You can access the active record using the ActiveRecord property. If a cell was activated within that record, you can access it through the ActiveCell property. It is common to call attention to the active object through either a distinct Style Trigger based on their IsActive property, or the record selector. The record selector can be positioned (or hidden) at the control or Field Layout level using the RecordSelectorLocation property, and styled through the RecordSelectorStyle property.

key areas of selection

The above screen shot illustrates an extended record selection scenario, highlighting the active record and record selector on a xamDataGrid.

More advanced selection handling scenarios can be handled by attaching an event handler to the SelectedItemChanging and SelectedItemChanged events that all DataPresenterBase-derived controls must fire when selection is enabled, and the selected item or items have changed.

For example, you can handle the SelectedItemChanging event to examine the NewSelection. After evaluating a business rule that restricts what items are allowed to be selected in your application’s current state, you can cancel the selection by setting the Cancel to True.

The selection infrastructure for DataPresenterBase-derived controls has been abstracted behind interfaces, which you can use to deal with the most advanced selection scenarios. All of the selectable items you have learned about in this topic (cells, records, and fields) implement the ISelectableItem interface, which allows them to be selectable by the control infrastructure. The DataPresenterBase class implements the ISelectionHost interface that is responsible for many of the finer aspects of selection, including dragging, dealing with translating a finer-grained ISelectableItem (e.g., a cell) into a coarser-grained ISelectableItemand (e.g., a record) based on the semantics of the ISelectionHost’s presentation, and the speed of auto-scrolling during the selection of a range spanning multiple pages at one time.

Clearing Selected Records in the xamDataGrid Control

To clear selected records in the xamDataGrid, CTRL + click the selected records.