Search code examples
c#winformsdatagridviewvirtualmode

WinForms.DataGridView VirtualMode Collapsing rows


I am working on a WinForms Application, that have a DataGridView, this Control emulates a TreeView, so the RowCount changes drastically. I am having a performance issue when collapsing rows...

Example:

// dataGrid.VirtualMode = true;
// dataGrid.RowCount = 100.000;
dataGrid.RowCount = 2; // Is too Slow!

Solution

  • Since you using VirtualMode, it is usually much faster to do like this:

    dataGrid.Rows.Clear();
    dataGrid.RowCount = 2;