Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a grid view which displays images opened from a folder. Once i click on an image from the gridview it shows in my picturebox to enlarge. But when i click on a different image in the gridview it throughs an error stating that i have a negative number and needs to be corrected. Here is the code i have once an image is selected in the gridview:

C#
private void dataViewImages_CellContentClick(object sender, DataGridViewCellEventArgs e)
{           
      string pic = dataViewImages.SelectedCells[e.RowIndex].ToString();
      pic = this._files[e.RowIndex];
      this.Text = pic;
      MessageBox.Show(pic);
      pictureBox.Image = Image.FromFile(pic);
      tsbSave.Enabled = true;
      tsbRotate.Enabled = true;
      tsbCCRotate.Enabled = true;
      saveToolStripMenuItem1.Enabled = true;
      saveToolStripMenuItem.Enabled = true;
}
Posted
Updated 16-Mar-10 4:42am
v4

1. You are not using numImagesRequired anywhere. Why do you need it?
2. Can you spot the problem with these lines:

C#
string pic = dataViewImages.SelectedCells[index].ToString();
                pic = this._files[index];


3. Why do need that for loop?

I would suggest to have a hidden column with path of the image displayed in each row. Then you can use following:

pic.Image = Image.FromFile(dataGridView.CurrentRow.Cells["hidden column index here"].Value.ToString());
 
Share this answer
 
v2
This[^] should help.

If you are not familiar with the technology, first thing you need is patience. One needs time to get familiar and understand any technology or anything for that matter.
 
Share this answer
 
Can you help me some more with this? I am not very familiar with windows forms and datagrids and i am getting really confused. i tried to make the column hidden but then it would return an error column not found.
 
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