Skip to main content
All docs
V25.1
  • DevExpress v25.1 Update — Your Feedback Matters

    Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

    Take the survey Not interested

    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.v25.1.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.25.1.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