开发者

Winforms: Change Datagridview image on mouseover

开发者 https://www.devze.com 2023-01-18 02:07 出处:网络
I\'m having t开发者_JS百科rouble 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. H

I'm having t开发者_JS百科rouble 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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消