Xceed DataGrid for WPF v7.2 Documentation
AutoFilterControl Class
Members  Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace : AutoFilterControl Class
Control that is displayed in a column-manager cell when automatic filtering is enabled.
Syntax
'Declaration
 
<TemplatePartAttribute(Name="PART_DistinctValuesHost", Type=System.Windows.Controls.Primitives.Selector)>
<StyleTypedPropertyAttribute(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)>
<XmlLangPropertyAttribute("Language")>
<UsableDuringInitializationAttribute(True)>
<RuntimeNamePropertyAttribute("Name")>
<UidPropertyAttribute("Uid")>
<TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
<NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
Public Class AutoFilterControl 
   Inherits System.Windows.Controls.Control
'Usage
 
Dim instance As AutoFilterControl
[TemplatePart(Name="PART_DistinctValuesHost", Type=System.Windows.Controls.Primitives.Selector)]
[StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]
[XmlLangProperty("Language")]
[UsableDuringInitialization(true)]
[RuntimeNameProperty("Name")]
[UidProperty("Uid")]
[TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
[NameScopeProperty("NameScope", System.Windows.NameScope)]
public class AutoFilterControl : System.Windows.Controls.Control 
Remarks

If a column does not need to support automatic filtering, it is recommended to set its corresponding DataGridItemProperty's CalculateDistinctValues to false or set the DataGridCollectionViewSource or DataGridDetailDescription's DefaultCalculateDistinctValues properties to false and only set CalculateDistinctValues to true for the item properties that will support auto-filtering

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
All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
The first example demonstrates how to provide the ShipCountry column with a new style for its associated AutoFilterControl that will only allow single selection.
<Grid>
  <Grid.Resources>
  <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                      Source="{Binding Source={x:Static Application.Current},
                                                       Path=Orders}"
                                      AutoFilterMode="And"
                                      DistinctValuesConstraint="Filtered"
                                      AutoCreateItemProperties="False">      
       <xcdg:DataGridCollectionViewSource.ItemProperties>
         <xcdg:DataGridItemProperty Name="ShipCountry"
                                          Title="Country"/>
         <xcdg:DataGridItemProperty Name="ShipCity"
                                    Title="City"/>
        <xcdg:DataGridItemProperty Name="ShipAddress"
                                   Title="Address"/>
        <xcdg:DataGridItemProperty Name="ShipPostalCode"
                                   Title="Postal Code"/>
         <xcdg:DataGridItemProperty Name="ShipName"
                                    Title="Name"
                                    CalculateDistinctValues="False"/>
         <xcdg:DataGridItemProperty Name="OrderDate"
                                    Title="Order Date"
                                    CalculateDistinctValues="False"/>              
         <xcdg:DataGridItemProperty Name="Freight"
                                    CalculateDistinctValues="False"/>
      </xcdg:DataGridCollectionViewSource.ItemProperties>
    </xcdg:DataGridCollectionViewSource> 
     <Style x:Key="autoFilterControlStyle"
       TargetType="{x:Type xcdg:AutoFilterControl}">
       <Setter Property="Template">
         <Setter.Value>
           <ControlTemplate>
             <ListBox x:Name="PART_DistinctValuesHost"
                      SelectionMode="Single"/>
           </ControlTemplate>
         </Setter.Value>
       </Setter>
     </Style>
  </Grid.Resources>

  <xcdg:DataGridControl x:Name="OrdersGrid"
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}">
    <xcdg:DataGridControl.Columns>
     <xcdg:Column FieldName="ShipCountry"
                  AutoFilterControlStyle="{StaticResource autoFilterControlStyle}"/>
    </xcdg:DataGridControl.Columns>
  </xcdg:DataGridControl>
</Grid>
The second example demonstrates how to use a ComboBox as an auto-filter control to automatically filter the content of the ShipCountry column. ComboBox controls do not support multiple selections; therefore, the values of the target column will only be filtered by 1 value. Since, by default, the auto-filter control in the column-manager-cell drop downs support multiple selections, it is recommended to deactivate the drop down by setting the AllowAutoFilter property of the ColumnManagerRow to false to hide the column-manager cells' auto-filter controls and prevent unexpected synchronization behavior between the controls that have the same auto-filter target column or different selection modes.
<Grid>
  <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                       Source="{Binding Source={x:Static Application.Current},
                                                        Path=Orders}"
                                       AutoFilterMode="And"
                                       DefaultCalculateDistinctValues="False"
                                       AutoCreateItemProperties="False">
      <xcdg:DataGridCollectionViewSource.ItemProperties>
        <xcdg:DataGridItemProperty Name="ShipCountry"
                                   Title="Country"
                                   CalculateDistinctValues="True"/>
        <xcdg:DataGridItemProperty Name="ShipCity"
                                   Title="City"/>
        <xcdg:DataGridItemProperty Name="ShipAddress"
                                   Title="Address" />
        <xcdg:DataGridItemProperty Name="ShipPostalCode"
                                   Title="Postal Code"/>
        <xcdg:DataGridItemProperty Name="ShipName"
                                   Title="Name"/>
        <xcdg:DataGridItemProperty Name="OrderDate"
                                   Title="Order Date"/>
        <xcdg:DataGridItemProperty Name="Freight"/>
      </xcdg:DataGridCollectionViewSource.ItemProperties>
    </xcdg:DataGridCollectionViewSource>
  </Grid.Resources>

  <DockPanel>
    <StackPanel Orientation="Horizontal"
                DockPanel.Dock="Top">
      <xcdg:AutoFilterControl x:Name="ShipCountryAutoFilterControl"
                              AutoFilterColumn="{Binding ElementName=OrdersGrid, Path=Columns[ShipCountry]}"
                              AutoFilterContext="{Binding ElementName=OrdersGrid, Path=DataGridContext}">
        <xcdg:AutoFilterControl.Template>
          <ControlTemplate TargetType="{x:Type xcdg:AutoFilterControl}">
            <ComboBox x:Name="PART_DistinctValuesHost"
                      Width="125" />
          </ControlTemplate>
        </xcdg:AutoFilterControl.Template>
      </xcdg:AutoFilterControl>

      <Button Content="Clear Filter"
              Command="xcdg:AutoFilterControl.ClearAutoFilterValues"
              CommandTarget="{Binding ElementName=ShipCountryAutoFilterControl}"/>       
    </StackPanel>

    <xcdg:DataGridControl x:Name="OrdersGrid"
                          ItemsSource="{Binding Source={StaticResource cvs_orders}}">
      <xcdg:DataGridControl.View>
        <xcdg:TableView UseDefaultHeadersFooters="False">
          <xcdg:TableView.FixedHeaders>
              <DataTemplate>
                <xcdg:GroupByControl />
              </DataTemplate>
              <DataTemplate>
                <xcdg:ColumnManagerRow AllowAutoFilter="False" />
              </DataTemplate>
            </xcdg:TableView.FixedHeaders>
          </xcdg:TableView>
        </xcdg:DataGridControl.View>
      </xcdg:DataGridControl>
    </DockPanel>
  </Grid>
Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Control
                     Xceed.Wpf.DataGrid.AutoFilterControl

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

Reference

AutoFilterControl Members
Xceed.Wpf.DataGrid Namespace