|
I want to implement a customized DataGridViewCell so when my mouse is over the cell, its outlook changes. I found an article from MSDN teaching how to implement a DataGridViewRolloverCell: when you move mouse over the cell, its borders change color to red. The example works fine. In the example, rows are added directly to the grid. I change the example so I use data binding to fill the grid. But after the change, I find a problem, after the form is opened, I move my mouse to a cell and its outlook doesn't get changed. Only after I select any cell of the same row does the cell's outlook changes when mouse is on it. In the example code, there is a DataGridViewRolloverCell class. Its Paint, OnMouseEnter, OnMouseLeave methods are overriden. OnMouseEnter and OnMouseLeave methods only call InvalidateCell method. As explained in the documentation, when InvalidateCell is called, it forces the cell to repaint itself, thus the Paint method gets called. In the Paint method, the cell paints its borders in red color. When the grid initializes and mouse enters a cell in a row such that no cell in that row has been selected before, InvalidateCell method of the cell gets called but the Paint method never gets fired. Only after I select the cell once, later on, the InvalidateCell method triggers the Paint method. I guess it is related to some optimization of the grid when data binding is used but couldn't find the real answer as well as the solution. Anyone can help? Thank you.
|