Skip to main content
All docs
V24.2

DataControlBase.CustomUniqueValuesCommand Property

Gets or sets a command that populates a column’s Drop-down Filter with unique values.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.2.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public ICommand<UniqueValuesArgs> CustomUniqueValuesCommand { get; set; }

Property Value

Type Description
ICommand<UniqueValuesArgs>

A command that populates a column’s Drop-down Filter with unique values.

Remarks

Bind a command to the CustomUniqueValuesCommand property to maintain a clean MVVM pattern. The command works like a CustomUniqueValues event handler and allows you to specify a custom set of unique values in a View Model.

The GridControl executes the command bound to the CustomUniqueValuesCommand property before a user opens a column’s Drop-down Filter. This command allows you to manually specify filter values.

<dxg:GridControl ItemsSource="{Binding Products}" 
                 AutoGenerateColumns="AddNew" 
                 CustomUniqueValuesCommand="{Binding CustomUniqueValuesCommand}"/>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
using DevExpress.Xpf.Data;

// ...

[Command]
public void CustomUniqueValues(UniqueValuesArgs args) {
    if (args.FieldName == "CategoryName") {

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

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

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

        args.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.24.2.Extensions.dll library to obtain unique values.

[Command]
public void CustomUniqueValues(UniqueValuesArgs args) {
    if (args.FieldName == "CategoryName") {
        args.UniqueValuesAndCountsAsync = Task.Run(() => {
            return GetProductsQueryCore().DistinctWithCounts(args.FieldName);
        }
    }
}
See Also