Click here to Skip to main content
15,920,630 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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]; //exception occurs here

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
Posted

1 solution

I don't see what "curr" is in your code?
 
Share this answer
 
v2
Comments
manumith 25-Apr-11 17:03pm    
curr is the object that I receive from the dl and curr.sequence() returns int value.
StM0n 25-Apr-11 17:11pm    
Should be interresting to check, what "curr.sequence()-1" tend to be... could you check it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900