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
    

    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