views:

75

answers:

2

I'm having trouble changing the image in a DataGridViewImageCell on mouseover. According to a few sources it should be as simple as changing the value of the cell to the desired image. However, nothing seems to happen when I try this. Here is the code:

private void dgvThingProgramsOnPlace_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == dgvThingProgramsOnPlace.ColumnCount - 1)
            {
                dgvThingProgramsOnPlace.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Image.FromFile(@"C:\Users\suan\Desktop\temp\icons\raster\gray_dark\x_16x16_red_custom.png");
            }
        }

Any ideas?

UPDATE: I've checked the debugger and the breakpoint is hit. The image paths are also definitely different. The problem is, the new image value is not getting assigned for some reason. In the debugger the before value == the after value...strange

+1  A: 

Some things you should try:

  1. call grid refresh and see if anything happens.
  2. check console for errors after executing this code.
  3. Application.DoEvents might also do the job

Hope this will help.

Chen Kinnrot
+1  A: 

Wow finally got it working. Turns out I accidentally turned VirtualMode on for that dataGridView.

Suan