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.v24.2.Core.dll
NuGet Package: DevExpress.Wpf.Grid.Core
#Declaration
#Event Data
The CustomUniqueValues event's data class is CustomUniqueValuesEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Async |
Gets an Async |
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 Routed |
Include |
Gets whether a drop-down filter’s values are displayed with ignoring filters by other columns. |
Original |
Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.
Inherited from Routed |
Round |
Gets or sets whether to ignore time values when you filter by Date |
Routed |
Gets or sets the Routed |
Source |
Gets a control (Grid |
Unique |
Gets or sets unique values. |
Unique |
Gets or sets unique values and their counts. |
Unique |
Gets or sets a task that allows you to asynchronously return unique values and their counts. |
Unique |
Gets or sets a task that allows you to asynchronously return unique values. |
The event data class exposes the following methods:
Method | Description |
---|---|
Invoke |
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 Routed |
On |
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 Routed |
#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.24.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.