I have a datagridview in a winform application, that gets data from an external dll and displays it dynamically.
As the new rows are getting added I want to show the newly added row to the user (so that the old rows keep moving upwards).
I am adding the new rows and showing the last added row as follows
string[] currentRow = new string[5];
currentRow[0] = curr.sequence().ToString();
currentRow[1] = typeString;
currentRow[2] = curr.stat().ToString();
currentRow[3] = detail;
currentRow[4] = curr.timestamp().ToString();
this.dataGridView1.Rows.Add(currentRow);
this.labelCount.Text = curr.sequence().ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[curr.sequence()-1].Cells[0];
I am getting an exception of
[System.ArgumentOutOfRangeException] = {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}.
at the line where I set the CurrentCell.
Although it occurly at random rows everytime. Sometime it occurs as early as 25th row. Other times at 1000th row.
What could be causing it? I see that the sequence is displayed correctly at labelbox.
Please help.
Thanks in advance