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:
- call grid refresh and see if anything happens.
- check console for errors after executing this code.
- Application.DoEvents might also do the job
Hope this will help.
精彩评论