I have a DGV without data binding (no data source, etc., added manually). To filter it, I did a loop check and correctly determined the properties of the strings. This worked well with smaller test suites, but does not fully work with large ones. 1 thousand Rows filtered at 5000 / sec. 10 thousand lines, filtered only ~ 250 / sec. 50k in just 40 seconds. My guess about what happens is that every time I change the visibility of the rows, the DGV rebuilds the list of displayed rows, turning the filtering process into an O (n ^ 2) operation.
Although even 10k lines indicate that the user is abusing the system; misbehaving needs to be taken into account, so I need to do something different. Is there a faster way to filter a large number of rows than what I'm doing now, without using data binding, or do I need to refuse to clear / recreate all rows (for a reasonable amount of data, this is much slower)?
// psuedocode. runs slowly if more than a few thousand rows.
foreach (DataGridViewRow row in myDGV)
{
row.Visible = CalculateFilter (row);
}
c # filter datagridview
Dan neely
source share