WinUI | ComponentOne
Controls / FlexGrid / Search
In This Topic
    In This Topic

    You can search data in FlexGrid using full text filtering feature wherein the grid's data source is filtered based on the user input to return the search results. The FullTextFilterBehaviour class helps to implement this feature. The FilterEntry property of this class associates a text box with the FlexGrid control. As soon as the user inputs a value in this text box, the FlexGrid control is filtered as shown in the GIF below.

    However, you can alter this behavior to filter the text after entering complete value using Mode property of the FullTextFilterBehaviour class, which accepts values from the FullTextFilterMode enumeration.

    By default, filtering is applied to the data source of FlexGrid. In case a DataCollection is used as FlexGrid's data source, filtering is applied to the DataCollection, and this impacts all the controls bound to the same DataCollection.

    Moreover, you can customize the filtering behavior using the MatchCaseMatchNumbersMatchWholeWord or TreatSpacesAsAndOperator properties which allow you to filter data by matching case, whole word, number or treat space as AND operator respectively. In addition, you can also specify the delay time used to filter after the last typed character using the Delay property.

    In XAML

    The following markup binds a text box to search and filter across all columns on the grid.

    Copy Code
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            <input:C1TextBox x:Name="filter" Margin="4" />
            <StackPanel Orientation="Horizontal" Grid.Row="1">
                <CheckBox x:Name="matchCaseCheckbox" Content="Match case" Margin="4"/>
                <CheckBox x:Name="matchWholeWordCheckBox" Content="Match whole word" Margin="4" />
                <CheckBox x:Name="treatSpacesAsAndOperator" Content="Treat Spaces As And Operator" Margin="4" IsChecked="True" />
                <CheckBox x:Name="matchNumbers" Content="Match Numbers" Margin="4" IsChecked="True"/>
            <c1:FlexGrid x:Name="flexGrid1" IsReadOnly="True" Grid.Row="2">
                    <c1:FullTextFilterBehavior FilterEntry="{Binding ElementName=filter}" 
                                         MatchWholeWord="{Binding IsChecked, ElementName=matchWholeWordCheckBox}" 
                                         MatchCase="{Binding IsChecked, ElementName=matchCaseCheckbox}"
                                         TreatSpacesAsAndOperator="{Binding IsChecked, ElementName=treatSpacesAsAndOperator}"
                                         MatchNumbers="{Binding IsChecked, ElementName=matchNumbers}" />

    In Code

    The following code sets the entry field and performs search and filtering across all columns on the grid.

    Copy Code
    public FullTextFilter()
        var data = Customer.GetCustomerList(100);
        flexGrid1.ItemsSource = data;
        flexGrid1.MinColumnWidth = 85;