Click here to Skip to main content
15,791,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am developing a picture viewer window application in c# .net in Microsoft visual studios 2008. I am stuck on how to get a selected thumbnail image from the gridview to be displayed in the Picturebox.

Here is the code i used:
private void dataViewImages_CellContentClick(object sender, DataGridViewCellEventArgs e)
   string pic = dataViewImages.SelectedRows[0].ToString();
   pictureBox.Image = Image.FromFile(pic);
   tsbSave.Enabled = true;
   tsbRotate.Enabled = true;
   tsbCCRotate.Enabled = true;

The error message i am getting is:

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

i know it will have to do with the ...SelectedRows[0] but at the same time i don't know how to fix it.
Updated 13-Mar-10 23:27pm

1 solution

Check if there is any selected or not. Place a check that if there is any selected row or not before you use the array.
Share this answer

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