Skip to main content
A newer version of this page is available. .

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.v21.2.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event CustomUniqueValuesEventHandler CustomUniqueValues

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.

The event data class exposes the following methods:

Method Description
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

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.21.2.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);
        }
    }
}

If you want to maintain a clean MVVM pattern and specify a custom set of unique values in a View Model, create a command and bind it to the CustomUniqueValuesCommand property.

See Also