wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-c417dae9.md
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.2.Core.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public ICommand<UniqueValuesArgs> CustomUniqueValuesCommand { get; set; }
Public Property CustomUniqueValuesCommand As ICommand(Of UniqueValuesArgs)
| Type | Description |
|---|---|
| ICommand<UniqueValuesArgs> |
A command that populates a column’s Drop-down Filter with unique values.
|
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();
});
}
}
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
Imports DevExpress.Xpf.Data
<Command>
Public Sub CustomUniqueValues(ByVal args As UniqueValuesArgs)
If args.FieldName = NameOf(Product.ProductName) Then
args.UniqueValues = ProductsDataModel.GetProducts()
.GroupBy(Function(x) x.ProductName)
.[Select](Function(x) x.Key)
.ToArray()
args.UniqueValuesAsync = Task.Run(Function() ProductsDataModel.GetProducts()
.GroupBy(Function(x) x.ProductName)
.[Select](Function(x) x.Key)
.Cast(Of Object)()
.ToArray())
End If
End Sub
If your data source implements the IQueryable interface, you can use the GridQueryableExtensions.Distinct and GridQueryableExtensions.DistinctWithCounts methods from the DevExpress.Xpf.Grid.25.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);
}
}
}
<Command>
Public Sub CustomUniqueValues(ByVal args As UniqueValuesArgs)
If args.FieldName = "CategoryName" Then
args.UniqueValuesAndCountsAsync = Task.Run(Function() GetProductsQueryCore().DistinctWithCounts(args.FieldName))
End If
End Sub
See Also