I've made a DataGradView in C# which allows me to collapse and expand rows. Looks like this:
At startup i want to collapse all customers with multiple entrys. Like the one shown in picture. Works well if the total number of customers is < 10.000
If total number of customer is > 10.000
it takes a few minutes to go.
Code to collapse all customers:
int number = 0;
int oldnumber = 0;
int parent = 0;
foreach (CustomDataGridViewRow row in dataGridView1.Rows)
{
try
{
number = int.Parse(row.Cells[1].Value.ToString());
if (number != oldnumber && int.Parse(dataGridView1.Rows[row.Index + 1].Cells[1].Value.ToString()) == number)
{
row.Is_expander = true;
parent = row.Index;
}
if (number == oldnumber)
{
row.hide(parent);
}
oldnumber = number;
}
catch { }
}
foreach row which has to collapse i call row.hide(parent)
, which set the visibility to false and saves the parent index.
foreach parent row an icon will be drawn
Can you guess why it takes so long to hide all these rows? Maybe after each hidden row screen draws again? Maybe i am doing unnecessary or heavy-performance stuff in loop? I have no idea