How to search the empty rows in WinForms DataGrid?
WinForms DataGrid (SfDataGrid) allows you to search and filter empty rows by customizing the SearchController.
public Form1()
{
InitializeComponent();
sfDataGrid1.SearchController = new SearchControllerExt(sfDataGrid1, panel);
}
public class SearchControllerExt : SearchController
{
SearchPanel searchPanel;
public SearchControllerExt(SfDataGrid grid, SearchPanel panel) :
base(grid)
{
searchPanel = panel;
this.AllowHighlightSearchText = false;
}
protected override bool FilterRecords(object dataRow)
{
if (this.Provider == null)
Provider = this.DataGrid.View.GetPropertyAccessProvider();
if (searchPanel.chkEmptyRows.Checked)
{
for (int i = 0; i < this.DataGrid.Columns.Count; i++)
{
var col = this.DataGrid.Columns[i];
var cellvalue = Provider.GetFormattedValue(dataRow, col.MappingName);
if (cellvalue == null)
continue;
else
return false;
}
return true;
}
else if (searchPanel.chkNonEmpty.Checked)
{
for (int i = 0; i < this.DataGrid.Columns.Count; i++)
{
var col = this.DataGrid.Columns[i];
var cellvalue = Provider.GetFormattedValue(dataRow, col.MappingName);
if (cellvalue != null)
continue;
else
return false;
}
return true;
}
else if(searchPanel.chkEmptyCell.Checked)
{
for (int i = 0; i < this.DataGrid.Columns.Count; i++)
{
var col = this.DataGrid.Columns[i];
var cellvalue = Provider.GetFormattedValue(dataRow, col.MappingName);
if (cellvalue == null)
return true;
else
continue;
}
return false;
}
else
return base.FilterRecords(dataRow);
}
} Take a moment to peruse the WinForms DataGrid - Search documentation, where you can find about search with code examples.
Conclusion
I hope you enjoyed learning about how to search the empty rows in DataGrid .
You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations WinForms DataGrid documentation
and how to quickly get started for configuration specifications. You can also explore our WinForms DataGrid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!