DataFilter for WinForms
フィルタ
DataFilter > フィルタ

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:

'AutoGenerateFiltersをtrueに設定すると、フィルタが自動的に生成します
c1DataFilter1.AutoGenerateFilters = true
c1DataFilter1.DataSource = _table
c1DataFilter1.ShowToolTips = true
//AutoGenerateFiltersをtrueに設定すると、フィルタが自動的に生成します
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.

'RangeFilterを追加します
Dim rangeFilter As RangeFilter = New RangeFilter("UnitPrice")
        
'ヘッダーのテキストを設定します
rangeFilter.HeaderText = "Unit Price"
        
'RangeFilterの最小値・最大値を設定します
rangeFilter.Minimum = 0
rangeFilter.Maximum = 100
        
'エディタの種類を指定します
rangeFilter.EditorsType = C1.DataFilter.EditorsType.SpinEditor
        
'エディタを表示します
rangeFilter.EditorsVisible = true
        
'エディタの幅を設定します。
rangeFilter.EditorWidth = 50
        
'フィルタヘッダーに表示するためToolTipのテキストを設定します
rangeFilter.ToolTip = "Select the price range to perform " +
                      "filtering on the grid"
        
'DataFilterコントロールにフィルタを追加します
c1DataFilter1.Filters.Add(rangeFilter)
// RangeFilterを追加します
RangeFilter rangeFilter = new RangeFilter("UnitPrice");

//ヘッダーのテキストを設定します
rangeFilter.HeaderText = "Unit Price";

//RangeFilterの最小値・最大値を設定します
rangeFilter.Minimum = 0;
rangeFilter.Maximum = 100;

//エディタの種類を指定します
rangeFilter.EditorsType = C1.DataFilter.EditorsType.SpinEditor;

//エディタを表示します
rangeFilter.EditorsVisible = true;
            
//エディタの幅を設定します。
rangeFilter.EditorWidth = 50;

//フィルタヘッダーに表示するためToolTipのテキストを設定します
rangeFilter.ToolTip = "Select the price range to perform " + "filtering on the grid";

//DataFilterコントロールにフィルタを追加します
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.

 

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

//ブランドフィールド用に作成されているChecklistFilterをリセットします
private void resetbtn_Click(object sender, EventArgs e)
        {
            brandFilter.Reset();
        }