1 Replies - 1663 Views - Last Post: 04 December 2012 - 05:33 PM Rate Topic: -----

#1 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Memory exception from a datagrid

Posted 04 December 2012 - 11:19 AM

Hello DICs,
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[e.RowIndex].Cells[e.ColumnIndex].Value = imThumb;

But every time I run the code I have this exception


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?

Is This A Good Question/Topic? 0
  • +

Replies To: Memory exception from a datagrid

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 6110
  • View blog
  • Posts: 21,029
  • Joined: 05-May 12

Re: Memory exception from a datagrid

Posted 04 December 2012 - 05:33 PM

Instead of pressing F5, have you broken into the debugger and looked at the full callstack (including looking into the unmanaged code)? That would be very informative to point at the issue.

Of the top of my head, I suspect that you installed a program that runs as a shell extension, and the shell extension doesn't behave too well when running within the context of the file explorer running inside the Open File Dialog.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1