Xceed DataGrid for WPF v7.2 Documentation
QueryDistinctValue Event
Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace > DataGridItemPropertyBase Class : QueryDistinctValue Event
Raised to allow custom distinct values to be provided.
Syntax
'Declaration
 
Public Event QueryDistinctValue As EventHandler(Of QueryDistinctValueEventArgs)
'Usage
 
Dim instance As DataGridItemPropertyBase
Dim handler As EventHandler(Of QueryDistinctValueEventArgs)
 
AddHandler instance.QueryDistinctValue, handler
public event EventHandler<QueryDistinctValueEventArgs> QueryDistinctValue
Event Data

The event handler receives an argument of type QueryDistinctValueEventArgs containing data related to this event. The following QueryDistinctValueEventArgs properties provide information specific to this event.

PropertyDescription
Gets the original distinct value extracted from the underlying data source.  
Gets or sets the custom distinct value that replaces the one originally extracted from the underlying data source.  
Remarks
By default, the values that are displayed in the auto-filter drop down represent the distinct values as they are extracted from the underlying data source; however, custom distinct values can be provided for one or more item properties rather than the originally-extracted distinct values by handling their QueryDistinctValue event and returning the custom value.
Example
The following example demonstrates how to provide custom distinct values that will display the only the month in columns that display DateTime values and that will filter according to a value range for a decimal column.
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
  <Grid.Resources>
     <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                        Source="{Binding Source={x:Static Application.Current}, Path=Orders}"
                                        AutoFilterMode="And"
                                        DefaultCalculateDistinctValues="False">
        <xcdg:DataGridCollectionViewSource.ItemProperties>

          <xcdg:DataGridItemProperty Name="OrderDate"
                                     QueryDistinctValue="DataGridItemProperty_QueryDistinctValue_Date"
                                     CalculateDistinctValues="True"/>
          <xcdg:DataGridItemProperty Name="RequiredDate"
                                     QueryDistinctValue="DataGridItemProperty_QueryDistinctValue_Date"
                                     CalculateDistinctValues="True" />
          <xcdg:DataGridItemProperty Name="ShippedDate"
                                     QueryDistinctValue="DataGridItemProperty_QueryDistinctValue_Date"
                                     CalculateDistinctValues="True" />
          <xcdg:DataGridItemProperty Name="Freight"
                                     QueryDistinctValue="DataGridItemProperty_QueryDistinctValue_Range"
                                     CalculateDistinctValues="True" />
        </xcdg:DataGridCollectionViewSource.ItemProperties>
     </xcdg:DataGridCollectionViewSource>
   
  </Grid.Resources>
  <xcdg:DataGridControl x:Name="OrdersGrid"
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}"/>
</Grid>
Private Sub DataGridItemProperty_QueryDistinctValue_Date( ByVal sender As Object, ByVal e As QueryDistinctValueEventArgs )
  If Typeof e.DataSourceValue Is DateTime Then
    e.DistinctValue = CDate( e.DataSourceValue ).ToString( "MMMM" )
  End If
End Sub

Private Sub DataGridItemProperty_QueryDistinctValue_Range( ByVal sender As Object, ByVal e As QueryDistinctValueEventArgs )
  If Typeof e.DataSourceValue Is Decimal Then
    Dim value As Decimal = CDec( e.DataSourceValue )
    If value <= 100 Then
      e.DistinctValue = "0 - 100"
    ElseIf( value > 100 And value <= 500 ) Then
      e.DistinctValue = "101 - 500"
    Else
      e.DistinctValue = "500+"
    End If
  End If
End Sub
private void DataGridItemProperty_QueryDistinctValue_Date( object sender, QueryDistinctValueEventArgs e )
{
 if( e.DataSourceValue is DateTime )
 {
   e.DistinctValue = ( ( DateTime )e.DataSourceValue ).ToString( "MMMM" );
 }
}

private void DataGridItemProperty_QueryDistinctValue_Range( object sender, QueryDistinctValueEventArgs e )
{
 if( e.DataSourceValue is decimal )
 {
   decimal value = ( decimal )e.DataSourceValue;
   if( value <= 100 )
   {
     e.DistinctValue = "0 - 100";
   }
   else if( value > 100 && value <= 500 )
   {
     e.DistinctValue = "101 - 500";
   }
   else
   {
     e.DistinctValue = "500+";
   }
 }
}
Requirements

Target Platforms: Windows 11, Windows, 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also