Back to Devexpress

InfiniteAsyncSource.GetUniqueValues Event

wpf-devexpress-dot-xpf-dot-data-dot-infiniteasyncsource.md

latest6.5 KB
Original Source

InfiniteAsyncSource.GetUniqueValues Event

Allows you to get unique values.

Namespace : DevExpress.Xpf.Data

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public event EventHandler<GetUniqueValuesAsyncEventArgs> GetUniqueValues
vb
Public Event GetUniqueValues As EventHandler(Of GetUniqueValuesAsyncEventArgs)

Event Data

The GetUniqueValues event's data class is GetUniqueValuesAsyncEventArgs. The following properties provide information specific to this event:

PropertyDescription
FilterGets the GridControl ‘s filtering. Inherited from GetUniqueValuesEventArgsBase.
PropertyNameGets the property name. Inherited from GetUniqueValuesEventArgsBase.
ResultGets or sets the result of the get unique values operation (only values).
ResultWithCountsGets or sets the result of the get unique values operation (values and their counts).

Remarks

View Example: How to Bind to InfiniteAsyncSource

Handle the GetUniqueValues event to show unique values in a column’s drop-down filter. You can also show counts of these values.

To show only unique values , get a list of these values and specify the GetUniqueValuesAsyncEventArgs.Result property.

To show unique values with their counts , get a list of these values with counts and specify the GetUniqueValuesAsyncEventArgs.ResultWithCounts property.

csharp
source.GetUniqueValues += (o, e) => {
    if (e.PropertyName == "User") {
        e.ResultWithCounts = Task.Run(() => {
            return GetIssueDataQueryable().DistinctWithCounts(e.PropertyName);
        });
    } 
    e.Result = Task.Run(() => {
        return GetIssueDataQueryable().Distinct(e.PropertyName);
    });
};
vb
AddHandler source.GetUniqueValues, Sub(o, e)
    If e.PropertyName = "User" Then
        e.ResultWithCounts = Task.Run(Function()
            Return GetIssueDataQueryable().DistinctWithCounts(e.PropertyName)
        End Function)
    End If
    e.Result = Task.Run(Function()
        Return GetIssueDataQueryable().Distinct(e.PropertyName)
    End Function)
End Sub

In the code sample above, a 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.

If you want to maintain a clean MVVM pattern and process unique values in a ViewModel, create a command and bind it to the InfiniteAsyncSource.GetUniqueValuesCommand property.

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetUniqueValues event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-bind-to-custom-service-with-restrictions/CS/MainWindow.xaml.cs#L27

csharp
source.GetUniqueValues += (o, e) => {
    e.Result = GetUniqueValuesAsync(e.PropertyName);

wpf-data-grid-use-virtual-sources-to-bind-to-in-memory-data/CS/MainWindow.xaml.cs#L37

csharp
source.GetUniqueValues += (o, e) => {
    if(e.PropertyName == "Priority") {

wpf-data-grid-bind-to-infiniteasyncsource/CS/InfiniteAsyncSourceSample/MainWindow.xaml.cs#L26

csharp
source.GetUniqueValues += (o, e) => {
    if(e.PropertyName == "Priority") {

wpf-data-grid-bind-to-custom-service-with-restrictions/VB/MainWindow.xaml.vb#L20

vb
AddHandler source.FetchRows, Sub(o, e) e.Result = FetchRowsAsync(e)
AddHandler source.GetUniqueValues, Sub(o, e) e.Result = GetUniqueValuesAsync(e.PropertyName)
Me.grid.ItemsSource = source

wpf-data-grid-use-virtual-sources-to-bind-to-in-memory-data/VB/MainWindow.xaml.vb#L22

vb
AddHandler source.GetTotalSummaries, Sub(o, e) e.Result = GetTotalSummaries(e, getSourceTask)
AddHandler source.GetUniqueValues, Sub(o, e)
    If Equals(e.PropertyName, "Priority") Then

See Also

InfiniteAsyncSource Class

InfiniteAsyncSource Members

DevExpress.Xpf.Data Namespace