FlexGrid for WinForms | ComponentOne
In This Topic
    Search
    In This Topic

    With FlexGrid, you can easily perform search either on the entire grid or just a specific column. This topic discusses how you can enable search in FlexGrid.

    Search in Entire Grid

    To search the entire FlexGrid, you need to add the C1FlexGridSearchPanel control to the form and associate it with the grid to be searched using SetC1FlexGridSearchPanel method. The C1FlexGridSearchPanel control highlights the search results and filters the records having search results automatically. However, you can choose not to highlight the results by setting the HighlightSearchResults to false. It also provides a SearchMode property to set whether to start the search automatically or on hitting the Search button or Enter key. You can also set the watermark in search box as well as a time delay in search.

    Search in Entire Grid

    Use the code below to search the entire WinForms FlexGrid using SearchPanel.

    // Associate the search panel with flexgrid to be searched
    c1FlexGridSearchPanel1.SetC1FlexGridSearchPanel(c1FlexGrid1, c1FlexGridSearchPanel1);
    
    // Configure the search
    c1FlexGridSearchPanel1.HighlightSearchResults = true;
    c1FlexGridSearchPanel1.SearchMode = C1.Win.C1FlexGrid.SearchMode.Always; 
    c1FlexGridSearchPanel1.Watermark = "Search products";
    c1FlexGridSearchPanel1.SearchDelay = 2;    
    
    ' Associate the search panel with flexgrid to be searched
    c1FlexGridSearchPanel1.SetC1FlexGridSearchPanel(c1FlexGrid1, c1FlexGridSearchPanel1)
    
    ' Configure the search
    c1FlexGridSearchPanel1.HighlightSearchResults = True
    c1FlexGridSearchPanel1.SearchMode = C1.Win.C1FlexGrid.SearchMode.Always
    c1FlexGridSearchPanel1.Watermark = "Search products"
    c1FlexGridSearchPanel1.SearchDelay = 2
    

    Besides an in-built search panel, you can use ApplySearch method of the C1FlexGrid class to search data in the entire grid. The ApplySearch() method provides various overloads to perform search in FlexGrid as listed below:

    Overload Description
    ApplySearch(string search, SearchHighlightMode highlightMode) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlighted.
    ApplySearch(string search, SearchHighlightMode highlightMode, bool filter) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlighted and also defines if search result is filtered or not.
    ApplySearch(string search, SearchHighlightMode highlightMode, bool filter, bool onlyVisibleColumns) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlightedand also defines if search result is filtered or not. Additionally, this overload lets you apply search on only visible columns in the grid.
    ApplySearch(string search, SearchHighlightMode highlightMode, bool filter, bool onlyVisibleColumns, bool onlyVisibleRows) Applies search to the data on the grid depending on how the highlight mode has defined search result to be highlightedand also defines if search result is filtered or not. Additionally, this overload lets you apply search on only visible rows and columns in the grid.

    To apply search in FlexGrid using the ApplySearch() method, use the following code. This code searches for the occurrence of the word "Car" and highlights only the first search result. This example uses the sample created in Quick Start.

    C#
    Copy Code
    c1FlexGrid1.ApplySearch("Car", SearchHighlightMode.OnlyFirst);
    

    Search in Column

    To enable column-wise search, FlexGrid provides AutoSearch property of the C1FlexGrid class which accepts values from AutoSearchEnum enumeration. The enumeration lets you start downward column search from the first scrollable row or from the current cursor position. To search a value in a particular column, you need to keep the cursor in that column and type the value to be searched, and grid automatically jumps to the search result in that column. You can also set delay in search by setting the AutoSearchDelay property.

    Search in Column

    Following code enables column-wise search in the WinForms FlexGrid.

    //Enable column-wise search from top row  
    c1FlexGrid1.AutoSearch = C1.Win.C1FlexGrid.AutoSearchEnum.FromTop;
    c1FlexGrid1.AutoSearchDelay = 2;        
    
    'Enable column-wise search from top row  
    c1FlexGrid1.AutoSearch = C1.Win.C1FlexGrid.AutoSearchEnum.FromTop
    c1FlexGrid1.AutoSearchDelay = 2      
    
    See Also