[Root] / Xceed.Wpf.DataGrid Assembly / Xceed.Wpf.DataGrid Namespace / AutoFilterControl Class / AutoFilterContext Property
Example


In This Topic
    AutoFilterContext Property
    In This Topic
    Gets or sets the auto-filter control's data-grid context.
    Syntax
    'Declaration
     
    Public Property AutoFilterContext As DataGridContext
    'Usage
     
    Dim instance As AutoFilterControl
    Dim value As DataGridContext
     
    instance.AutoFilterContext = value
     
    value = instance.AutoFilterContext
    public DataGridContext AutoFilterContext {get; set;}

    Property Value

    A reference to the auto-filter control's DataGridContext.
    Remarks
    This property only needs to be set when the auto-filter control is used outside of a grid.
    Example
    All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
    The following 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">
          <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>
    Supported Frameworks

    .NET: net5.0, net5.0-windows, net6.0, net6.0-macos, net6.0-windows, net7.0, net7.0-macos, net7.0-windows, net8.0, net8.0-browser, net8.0-macos, net8.0-windows, net9.0, net9.0-browser, net9.0-macos, net9.0-windows, net10.0, net10.0-browser, net10.0-macos, net10.0-windows.

    .NET Framework: net20, net35, net40, net403, net45, net451, net452, net46, net461, net462, net463, net47, net471, net472, net48, net481.

    See Also