In my code I need to remove rows from the DataGridView after a recurring interval, and so I call the following function when a timer expires:
private void removeRows(DataGridView dgv) {
foreach (DataGridViewRow row in dgv.Rows)
{
// if some condition holds
dgv.Remove(row);
}
dgv.Refresh();
}
I know the rows are successfully deleted from the DataGridView, though they still remains in the display for whatever reason. Any tips on what I might be doing wrong?
Don't you need to rebind the data grid?
dgrv.Datasource = [whatever data source];
dgrv.DataBind();
?
Sometimes refreshing the data gridview is not enough and its containing parent should be refreshed too.
Try this:
dgv.Refresh(); // Make sure this comes first
dgv.Parent.Refresh(); // Make sure this comes second
You could also edit your source and attach the new datasource to the control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With