Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello guys

i am getting this error

"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"


C#
private void ExcelDGV_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex != -1)
    {
        textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
    }
}


any help will be appreciated , thanks
Posted

1 solution

Two possibilities here:
1) RowIndex is out of the range,
2) Cells is out of the range,

If it isn't the RowIndex, then it has to be the Cells - are there any?
Or...should that be dataGridView1 at all? The method name implies the control is called ExcelDGV...

Use the debugger to look at the parts of the line and see what you do have.
 
Share this answer
 
Comments
aboda yehia 17-Aug-14 11:37am    
OMG , I am too stupid .. it had to be ExcelDGV , havenot slept since yesterday :)

Thanks Alot
OriginalGriff 17-Aug-14 11:38am    
You're welcome - I've had days like that as well! :laugh:
[no name] 17-Aug-14 11:40am    
Nicely spotted.

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