Articles in this section
Category / Section

How to Perform search functionality in Master-Details of WinForms DataGrid?

In WinForms DataGrid (SfDataGrid), the Master-details view enables searching of data through SearchController.Search method in the GridViewDefinition.DataGrid. Additionally, navigation to the previous and next cells matching the search text is supported using the SearchController.FindPrevious and SearchController.FindNext methods.

SfDataGrid detailsViewGrid;
this.sfDataGrid1.AutoGeneratingRelations += OnAutoGeneratingRelations;

private void OnAutoGeneratingRelations(object sender, AutoGeneratingRelationsEventArgs e)
{
    // To get the DeatilsView dataGrid
    detailsViewGrid = e.GridViewDefinition.DataGrid;
}

private void OnTextChanged(object sender, EventArgs e)
{
    // To perform search in DetailsView DataGrid
    detailsViewGrid.SearchController.Search(this.textBox1.Text);
}

private void previousButtonClick(object sender, EventArgs e)
{
    // To navigate the previous cell match with search text
    if (detailsViewGrid.SearchController.FindPrevious(this.textBox1.Text))
    {
        var detailsViewGrid = sfDataGrid1.GetDetailsViewGrid(this.sfDataGrid1.SearchController.CurrentRowColumnIndex.RowIndex);
        detailsViewGrid.MoveToCurrentCell(detailsViewGrid.SearchController.CurrentRowColumnIndex);
    }            
}

private void nextButtonClick(object sender, EventArgs e)
{
    // To navigate the next cell match with search text
    if (detailsViewGrid.SearchController.FindNext(this.textBox1.Text))
    {
        var detailsViewGrid = sfDataGrid1.GetDetailsViewGrid(this.sfDataGrid1.SearchController.CurrentRowColumnIndex.RowIndex);
        detailsViewGrid.MoveToCurrentCell(detailsViewGrid.SearchController.CurrentRowColumnIndex);
    }
}

Search


Take a moment to peruse the WinForms DataGrid - Search documentation, where you can find about the search with code examples.

View sample in GitHub.


Conclusion
I hope you enjoyed learning how to perform search functionality in master-Details of WF DataGrid.

You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms DataGrid example to understand how to create and manipulate data.


For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion, try our 30-day free trial to check out our other controls.


Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our  support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied