FlexReport for .NET | ComponentOne
Reports in WPF / Filter Data
In This Topic
    Filter Data
    In This Topic

    Filtering allows you to extract specific subsets of data that meet certain criteria. This is essential when you only need to view or work with a portion of the data that is relevant. Filtering helps in exploring and analyzing data more effectively by focusing on specific attributes or conditions. For example, filtering customer data based on location or purchase behavior can provide insights for targeted marketing strategies.

    In FlexReport, the data is filtered by using the Filter property of the DataSource class. Using a filter is similar to specifying a WHERE clause in the SQL statement. Suppose you want to know how many times a product is available in the loaded report using the product id (Pid) of the product. You need to add the following code to Filter the product detail corresponding to the product id.

    1. In XAML view, add a Label, TextBox, Button and a  FlexViewer  control.
    2. Set the Name property of the FlexViewer control to flexfilterviewer and  Button control to btnfilter.  Also, set the Content property of the Button control to Filter Report using Product ID and Lebel control to Enter Product ID , as shown in the following code snippet:
      C#
      Copy Code
      <c1:C1FlexViewer Name="flexfilterviewer" HorizontalAlignment="Left" Height="633" VerticalAlignment="Top" Width="958" Margin="0,28,0,0"/>
      <Button x:Name="btnfilter" Content="Filter Report using Product ID" Click="btnfilter_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="171"  Margin="300,5,0,0"/>
      <TextBox x:Name="txtpid" HorizontalAlignment="Left" Margin="150,5,0,0" VerticalAlignment="Top" Width="121"></TextBox>
      <Label Content="Enter Product ID:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="121"  Margin="43,0,0,0"/>
      
    3. Create a data table with the name GetMyDataTable and add the code to load and render the report as shown in DataTable object as DataSource section of the Data Binding topic.
    4. Add the following code in the Click event of the Button control for filtering the data in the report. In the code, the Filter property filters the data on the basis of value entered by the user in the textbox control.
      C#
      Copy Code
      flexReport.DataSource.Filter = "PiD ='" +txtpid.Text+"'";
      flexReport.Render();    
      
    5. Run the application to view the report in the flexfilterviewer control.
    6. Enter product id (Pid) ='P001' in the textbox control.
    7. Click the Filter Report using Product ID button to filter the data in the report. The records related to the product with Pid = 'P001' gets displayed in the report.

      FilterData