DataControlBase.CustomUniqueValues Event

Allows you to specify unique values displayed within a column's Drop-down Filter.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.1.Core.dll

Declaration

public event CustomUniqueValuesEventHandler CustomUniqueValues
Public Event CustomUniqueValues As CustomUniqueValuesEventHandler

Event Data

The CustomUniqueValues event's data class is CustomUniqueValuesEventArgs. The following properties provide information specific to this event:

Property Description
AsyncCompleted Gets an AsyncCompletedHandler delegate referencing a method that should be executed after the operation is completed.
Column Gets a column for which a drop-down filter is shown.
Filter Gets the current filter.
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
IncludeFilteredOut Gets whether a drop-down filter's values are displayed with ignoring filters by other columns.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoundDateTime Gets or sets whether to ignore time values when you filter by DateTime values.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Source Gets a control (GridControl or TreeListControl) that raised the event.
UniqueValues Gets or sets unique values.
UniqueValuesAndCounts Gets or sets unique values and their counts.
UniqueValuesAndCountsAsync Gets or sets a task that allows you to asynchronously return unique values and their counts.
UniqueValuesAsync Gets or sets a task that allows you to asynchronously return unique values.

Remarks

The CustomUniqueValues event fires before a column's drop-down filter is populated with unique column values. This event allows you to manually specify filter values.

<dxg:GridControl Name="gridControl" ItemsSource="{Binding Products}"
                 CustomUniqueValues="gridControl_CustomUniqueValues">
    <dxg:GridControl.Columns>
        <dxg:GridColumn FieldName="ProductName" IsSmart="True"/>
        <dxg:GridColumn FieldName="CategoryName" IsSmart="True"/>
    </dxg:GridControl.Columns>
    <dxg:GridControl.View>
        <dxg:TableView/>
    </dxg:GridControl.View>
</dxg:GridControl>
void gridControl_CustomUniqueValues(object sender, CustomUniqueValuesEventArgs e) {
    if (e.Column.FieldName == "CategoryName") {
        e.Handled = true;

        // Synchronously:
        // Specify the UniqueValues / UniqueValuesAndCounts property.

        e.UniqueValuesAndCounts = GetProductsQueryCore()
            .GroupBy(x => x.CategoryName)
            .Select(x => new ValueAndCount(x.Key, x.Count()))
            .ToArray();

        // Asynchronously:
        // Specify the UniqueValuesAsync / UniqueValuesAndCountsAsync property.

        e.UniqueValuesAndCountsAsync = Task.Run(() => {
            return GetProductsQueryCore()
                .GroupBy(x => x.CategoryName)
                .Select(x => new ValueAndCount(x.Key, x.Count()))
                .ToArray();
            });
    }
}

If your data source implements the IQueryable interface, you can use the GridQueryableExtensions.Distinct and GridQueryableExtensions.DistinctWithCounts methods from the DevExpress.Xpf.Grid.20.1.Extensions.dll library to obtain unique values.

void gridControl_CustomUniqueValues(object sender, CustomUniqueValuesEventArgs e) {
    if (e.Column.FieldName == "CategoryName") {
        e.Handled = true;
        e.UniqueValuesAndCountsAsync = Task.Run(() => {
            return GetProductsQueryCore().DistinctWithCounts(e.Column.FieldName);
        }
    }
}
See Also