I have a form with a datagridview
and there is an Image column in this grid
I want the user to double click the cell then he chooses an Image to be stored in that cell
So, I did this :
private void dgTicker_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == colImage.Index)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files (*.jpeg, *.png, *.jpg, *.gif)|*.jpeg;*.png;*.jpg;*.gif";
open.Multiselect = false;
if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Image im = Image.FromFile(open.FileName);
Image imThumb = im.GetThumbnailImage(50, 50, null, IntPtr.Zero);
if (e.RowIndex >= dgTicker.Rows.Count)
dgTicker.Rows.Add();
dgTicker.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = imThumb;
}
}
}
But every time I run the code I have this exception
Quote
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at this line
if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
and to my surprise when the exception appears and I press F5 again (while the exception is there) it goes on and open the dialog very normal
and I tried to put this code anywhere outside the double click event of the grid (like in the constructor or load event) it work very well, so I guessed that it is something with the grid itself
I searched a lot but in vain
tried all the solutions out there even those about changing options in the debugger itself.
Any ideas?

New Topic/Question
Reply




MultiQuote




|