Virtual Grids and OnCellMouseEnter events

Quick view: Changing the image in a DataGridViewImageCell to make it  act more like a button.

I have a datagridview in an interface that I am working on. (.NET 2.0) I didn’t see how to easily put an image in the DataGridViewButtonColumn so I chose to use a DataGridViewImageColumn and handle the click event for the cell as if it were a button.  I made two images for the “button,” one normal and one with a gold highlighted edge to use when OnCellMouseEnter fires.  But I could not get the image to respond to the OnCellMouseEnter event. I rechecked all the little details, making sure I was setting the right property (.value) to change the image, using the right column and row, etc.

 It finally occurred to me that the developer who originally made the gridview made it virtual. A ha! Virtual mode acts differently. So I got a little creative to keep track of the last cell that the mouse entered, and then changed the image in OnValueNeeded.

In retrospect, it is as easy as saying that virtual grids require you to use CellValueNeeded.

Advertisements

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: