New to Telerik UI for WPF? Download free 30-day trial

Display All Distinct Values

By default, the distinct values that a column shows will be limited to the first 1000 distinct values that are visible in this column. If other columns have an active filter that hides some of the data rows then these rows will not be considered when extracting the distinct values. You can control this behavior by attaching to the DistinctValuesLoading event of RadGridView and assigning a value to the ItemsSource property of the event arguments. This event will be fired each time the popup filtering control is about to be displayed. This event should be used solely for controlling the number of distinct values that the user will see. You can’t replace the original distinct values with values from another .NET Type since this would break the data engine. The distinct values that you assign to the ItemsSource property of the event arguments should always be of the same type as the data displayed in the column. If possible, you should always use RadGridView’s public method GetDistinctValues which has two overloads. Using the first overload you can tell RadGridView to provide all distinct values for a certain column by ignoring the currently active filters of other columns(Example 1). This is achieved by specifying false for the filter argument of the method. For example, if we have countries and players and we have filtered by CountryX, when we request all distinct players, if 'filter' is true we will get players from CountryX only. If 'filter' is false we will get all distinct players.

Example 1: The GetDistinctValues(GridViewColumn, Boolean) method returns the first 1000 distinct values for the given column.The Boolean('filter') parameter specifies whether distinct values should be filtered according to other columns' active filters.

private void OnRadGridViewDistinctValuesLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs e) 
{ 
    e.ItemsSource = ((Telerik.Windows.Controls.RadGridView)sender).GetDistinctValues(e.Column, false); 
} 
Private Sub OnRadGridViewDistinctValuesLoading(sender As System.Object, e As Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs) 
    e.ItemsSource = DirectCast(sender, Telerik.Windows.Controls.RadGridView).GetDistinctValues(e.Column, False) 
End Sub 

To control the maximum amount of distinct values displayed by the column you can use the second overload of the GetDistinctValues method which has one additional argument of type nullable integer called maximumValueCount. The value you provide will be used to limit the amount of distinct values returned(Example 2). If you supply a null value you will get absolutely all distinct values. Have in mind that displaying absolutely all distinct values may lead to performance issues.

Example 2: The GetDistinctValues(GridViewColumn, Boolean, Nullable(Int32)) method will force the column to display only the first 15 visible distinct values.The maximum amount of distinct values to return. If you specify null for the Nullable(Int32) parameter, then all distinct values will be returned.

private void OnRadGridViewDistinctValuesLoading2(object sender, Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs e) 
{ 
    e.ItemsSource = ((Telerik.Windows.Controls.RadGridView)sender).GetDistinctValues(e.Column, true, 15); 
} 
Private Sub OnRadGridViewDistinctValuesLoading2(sender As System.Object, e As Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs) 
    e.ItemsSource = DirectCast(sender, Telerik.Windows.Controls.RadGridView).GetDistinctValues(e.Column, True, 15) 
End Sub 

The column instance provided by the event arguments can help make adjustments for specific columns only.

Display Case Insensitive Distinct Values

By default, the distinct values are case sensitive. In order to populate them case insensitive and then filter on them, you can implement the following additional code(Example 3):

Example 3: Displaying case insensitive distinct values.

private void OnRadGridViewFiltered(object sender, Telerik.Windows.Controls.GridView.GridViewFilteredEventArgs e) 
{ 
    foreach (var item in e.ColumnFilterDescriptor.DistinctFilter.FilterDescriptors) 
    { 
        item.IsCaseSensitive = false; 
    } 
} 
 
private void OnRadGridViewDistinctValuesLoading3(object sender, Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs e) 
{ 
    e.ItemsSource = ((Telerik.Windows.Controls.RadGridView)sender).GetDistinctValues(e.Column, false).OfType<string>().Select(x => x.ToLower()).Distinct(); 
} 
Private Sub OnRadGridViewFiltered(sender As Object, e As Telerik.Windows.Controls.GridView.GridViewFilteredEventArgs) 
    For Each item In e.ColumnFilterDescriptor.DistinctFilter.FilterDescriptors 
        item.IsCaseSensitive = False 
    Next 
End Sub 
 
Private Sub OnRadGridViewDistinctValuesLoading3(sender As Object, e As Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs) 
    e.ItemsSource = DirectCast(sender, Telerik.Windows.Controls.RadGridView).GetDistinctValues(e.Column, False).OfType(Of String)().Select.Distinct() 
End Sub 
In this article