I need to delete top 1000 rows in a datagridview.
delegate void DeleteRowsCallback();
private static void Delete1KRows()
{
JSONTest form = (JSONTest)Application.OpenForms["JSONTest"];
if (form.GridTestReport.InvokeRequired)
{
DeleteRowsCallback d = new DeleteRowsCallback(Delete1KRows);
form.GridTestReport.Invoke(d);
}
else
{
for (int i = 0; i < 1000; i++ )
{
form.GridTestReport.Rows.RemoveAt(0);
}
}
}
This deletes the rows but takes lot of time. Also the UI is non-responsive when the delete is in progress. Any better way to delete multiple rows.
Thanks
As you are not using any binding or virtual mode, everytime you remove a row, the entire grid is refreshed. It would be painfully slow.
As you are dealing with large amount of data, use Virtual Mode
to efficietly update the grid.
See this MSDN link for more information. There is a Walkhrough available. It takes little time to setup but once it is done it would much faster ane makes life easier.
Also see Best Practices for Scaling the Windows Forms DataGridView Control to get the maximum out DataGridView
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments