Reports for WinForms | ComponentOne
C1.C1Report.4 Assembly / C1.C1Report Namespace / DataSource Class / Filter Property
Example

In This Topic
    Filter Property
    In This Topic
    Gets or sets the expression used to filter which data rows are included in the report.
    Syntax
    'Declaration
     
    Public Property Filter As String
    public string Filter {get; set;}
    Remarks

    Use the Filter property to restrict the records that you want to include in a report without modifying the RecordSource property.

    Using a filter is similar to specifying a WHERE clause in the SQL statement assigned to the RecordSource property. Both techniques will filter the data according to the condition specified. The difference is that the Filter property is applied to a table that has already been loaded in memory, while the WHERE statement causes only the filtered records to be loaded from the database into memory.

    When creating reports that include only small subsets large tables, the WHERE statement is a better option, because it doesn't require the entire table to be loaded into memory. On the other hand, if the table has already been loaded in memory, the Filter property is a better option, since it does not require any additional data to be loaded.

    The syntax for the filter expression is the same used to specify the System.Data.DataView.RowFilter property for System.Data.DataView objects. The expressions consist of conditions in the form ColumnNameOperatorValue, where ColumnName is the name of a column in the data source (optionally enclosed in square brackets), Operator is one of the regular Visual Basic comparison operators, and Value is a literal enclosed in single quotes. Conditions may be concatenated using AND and OR operators.

    Example
    The code below shows how to apply a filter to a data source using the Filter property and using a WHERE clause in a SQL statement:
    if (useFilterProperty)
    {
    	// load all records, filter in memory
        _c1r.DataSource.RecordSource = "SELECT * from Employees";
        _c1r.DataSource.Filter = "HireDate >= '1/1/1993' AND Country = 'UK'";
    }
    else
    {
    	// load selected records only
        _c1r.DataSource.RecordSource = "SELECT * from Employees " +
            "WHERE HireDate >= #1/1/1993# AND Country = 'UK'";
    See Also