DataFilter for WinForms | ComponentOne
Data Filters / Types of Filters
In This Topic
    Types of Filters
    In This Topic

    The DataFilter control supports five different kinds of filters namely, BoolFilter, RangeFilter, DateRangeFilter, ChecklistFilter and CalendarFilter, to filter different types of data. Corresponding to each filter, an accordion tab is added to the DataFilter control which contains the controls used to filter the data-aware control by a specific field. For example, 

    When the AutoGenerateFilters property of the C1DataFilter class is set to true, filters are automatically generated depending on the type of the fields present in the DataSource. These filters are added to the FilterCollection and can be accessed using Filters property of the C1DataFilter class.

    The following code demonstrates how filters can be automatically generated in the DataFilter control.

    'Setting AutoGenerateFilters to true generates the filters automatically. 
    c1DataFilter1.AutoGenerateFilters = true
    c1DataFilter1.DataSource = _table
    c1DataFilter1.ShowToolTips = true
    
    //Setting AutoGenerateFilters to true generates the filters automatically. 
    c1DataFilter1.AutoGenerateFilters = true; 
    c1DataFilter1.DataSource = _table;
    c1DataFilter1.ShowToolTips = true;
    

    To add filters programmatically to the DataFilter control, follow these steps:

    1. Create an instance of one of the different filter types, namely BoolFilter, RangeFilter, ChecklistFilter or DateRangeFilter. The instance accepts a parameter that is the name of the data field for which the filter is being defined.
    2. Specify the important properties related to the filter class.
    3. Finally, add the filter instance to the FilterCollection.

    To add a RangeFilter to the DataFilter control, use the following code. This code sets the header, editor type, editor width, tooltip, maximum value, and minimum value for the range filter.

    'Add RangeFilter
    Dim rangeFilter As RangeFilter = New RangeFilter("UnitPrice")
            
    'Set text for the header
    rangeFilter.HeaderText = "Unit Price"
            
    'Set minimum and maximum values for the RangeFilter
    rangeFilter.Minimum = 0
    rangeFilter.Maximum = 100
            
    'Specify the type of editor
    rangeFilter.EditorsType = C1.DataFilter.EditorsType.SpinEditor
            
    'Show the editor
    rangeFilter.EditorsVisible = true
            
    'Set the width of editor
    rangeFilter.EditorWidth = 50
            
    'Sets text of the ToolTip to appear on the filter header
    rangeFilter.ToolTip = "Select the price range to perform " +
                          "filtering on the grid"
            
    'Add filter to the DataFilter control
    c1DataFilter1.Filters.Add(rangeFilter)
    
    //Add RangeFilter
    RangeFilter rangeFilter = new RangeFilter("UnitPrice");
    
    //Set text for the header
    rangeFilter.HeaderText = "Unit Price";
    
    //Set minimum and maximum values for the RangeFilter
    rangeFilter.Minimum = 0;
    rangeFilter.Maximum = 100;
    
    //Specify the type of editor
    rangeFilter.EditorsType = C1.DataFilter.EditorsType.SpinEditor;
    
    //Show the editor
    rangeFilter.EditorsVisible = true;
                
    //Set the width of editor
    rangeFilter.EditorWidth = 50;
    
    //Sets text of the ToolTip to appear on the filter header
    rangeFilter.ToolTip = "Select the price range to perform " + "filtering on the grid";
    
    //Add filter to the DataFilter control
    c1DataFilter1.Filters.Add(rangeFilter);
    

    Reset Filters

    DataFilter also supports filter reset feature. This enables you to the reset the filter selection to its default value on the click of a button. You can use reset method to implement this feature on the filters. 

    As shown in the GIF below, all the filter selections are cleared after clicking on the reset filter button.

    Filter Reset

     To implement this feature, you can use the following code. In this code, reset method is applied on the brand filter.

    //Reset the ChecklistFilter created for brand field. 
    private void resetbtn_Click(object sender, EventArgs e)
            {
                brandFilter.Reset();
            }