Hiding Row in DataGridView Very Slow

Posted by Ed Schwehm on Stack Overflow See other posts from Stack Overflow or by Ed Schwehm
Published on 2010-03-20T13:45:13Z Indexed on 2010/03/20 13:51 UTC
Read the original article Hit count: 418

Filed under:
|
|
|

I have a DataGridView in a Winforms app that has about 1000 rows (unbound) and 50 columns. Hiding a column takes a full 2 seconds. When I want to hide about half the rows, this becomes a problem.

    private void ShowRows(string match)
    {
        this.SuspendLayout();
        foreach (DataGridViewRow row in uxMainList.Rows)
        {
            if (match == row.Cells["thisColumn"].Value.ToString()))
            { row.Visible = false; }
            else
            { row.Visible = true; }
        }
        this.ResumeLayout();
    }

I did some testing by adding by addingConsole.WriteLine(DateTime.Now)around the actions, androw.Visible = falseis definitely the slow bit. Am I missing something obvious, like setting IsReallySlow = false? Or do I have to go ahead and enable Virtual Mode and code up the necessary events?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#