Suan
Suan

Reputation: 37115

Winforms: Change Datagridview image on mouseover

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

Upvotes: 2

Views: 3080

Answers (2)

Suan
Suan

Reputation: 37115

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

Upvotes: 2

Chen Kinnrot
Chen Kinnrot

Reputation: 21015

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.

Upvotes: 1

Related Questions