GanttView for WPF | ComponentOne
In This Topic
    Custom Filtering
    In This Topic

    Besides the default filtering options that you get on the toolbar, the GanttView control also enables users create custom filters to suit their business needs. To achieve this, the control provides Advanced filter dialog, which is available under the Filter button on the toolbar. You can create your own filters by specifying fields in the FieldName and test condition in the Test field.

    The following image shows how the Advanced filter dialog appears.

    Advanced Filtering

    Creating Custom Filters in Code

    The C1GanttView class library includes various classes that can be used to create custom filters in code. For example, you can use the LateTasksFilter class to filter late tasks, or use ConditionTaskFilter and AdvancedFilter classes to filter tasks scheduled within a specific date range. Complete the following steps to create such filters in code. The following code example uses the sample created in the Quick Start section.

    1. In the XAML view, resize the GanttView control placed onto the MainWindow, and place two standard button controls to the form.
    2. Set the basic properties of the buttons in the XAML.
      XAML
      Copy Code
      <Button Content="Filter Tasks by Date" Width="110" />
      <Button Content="Filter Late Tasks" Width="114"/>
      
    3. Subscribe the Click events for the two buttons in the XAML view.
      XAML
      Copy Code
      <Button Content="Filter Tasks by Date" Width="110" Click="Button1_Click" />
      <Button Content="Filter Late Tasks" Width="114" Click=Button2_Click"/>
      
    4. Add the following code to the handler for Button1_Click event in the MainPage.xaml.cs file.
      Private Sub Button1_Click(sender As Object, e As RoutedEventArgs)
          Dim filter As New AdvancedFilter()
          ' Filter the tasks starting on April 8th, 2016...
          Dim startCondition As New ConditionTaskFilter()
          startCondition.FilterField = FilterField.Start
          startCondition.TestOperator = TestOperators.IsGreaterThanOrEqualTo
          startCondition.FilterValue = New DateTime(2016, 4, 8)
          filter.Conditions.Add(startCondition)
      
          ' Filter tasks finishing before or on May 10th, 2016...
          Dim finishCondition As New ConditionTaskFilter()
          finishCondition.FilterField = FilterField.Finish
          finishCondition.TestOperator = TestOperators.IsLessThanOrEqualTo
          finishCondition.FilterValue = New DateTime(2016, 5, 10)
          filter.Conditions.Add(finishCondition)
          gv.ApplyFilter(filter)
      End Sub
      
      private void Button1_Click(object sender, RoutedEventArgs e)
      {
          AdvancedFilter filter = new AdvancedFilter();
          // Filter the tasks starting on April 8th, 2016...
          ConditionTaskFilter startCondition = new ConditionTaskFilter();
          startCondition.FilterField = FilterField.Start;
          startCondition.TestOperator = TestOperators.IsGreaterThanOrEqualTo;
          startCondition.FilterValue = new DateTime(2016, 4, 8);
          filter.Conditions.Add(startCondition);
      
          // Filter tasks finishing before or on May 10th, 2016...
          ConditionTaskFilter finishCondition = new ConditionTaskFilter();
          finishCondition.FilterField = FilterField.Finish;
          finishCondition.TestOperator = TestOperators.IsLessThanOrEqualTo;
          finishCondition.FilterValue = new DateTime(2016, 5, 10);
          filter.Conditions.Add(finishCondition);
          gv.ApplyFilter(filter);
      }
      

      The above code filters tasks starting on 8-April-2016 and finishing before or on 10-May-2016.

    5. Add the following code to the handler for Button2_Click event in the MainPage.xaml.cs file.
      Private Sub Button2_Click(sender As Object, e As RoutedEventArgs)
          Dim filter As New LateTasksFilter(New DateTime(2016, 5, 10))
          gv.ApplyFilter(filter)
      End Sub
      
      private void Button2_Click(object sender, RoutedEventArgs e)
      {
          LateTasksFilter filter = new LateTasksFilter(new DateTime(2016, 5, 10));
          gv.ApplyFilter(filter);
      }
      

      The above code filters tasks whose start date is 10-May-2016 or beyond.

    6. Press F5 to run the application to see how the custom filter buttons get displayed in the output.

      Main Window

    On clicking the Filter Tasks by Date button, the GanttView displays tasks starting on 8-April-2016 and finishing before or on 10-May-2016, while on clicking the Filter Late Tasks, tasks with start date 10-May-2016 or beyond get displayed.