I have a number of questions regarding custom painting on a Datagridview control:
1. In which order are the different painting events (RowPrePaint, RowPostPaint, CellPainting, CellFormating, Paint etc) handled? Also is the CellClick event (and similar events) handled before or after the oainting event?
2. I know it's not possible to merge two column headers so I'm trying to paint my own headers. I'm doing this by using the first row as the header and painting on that row. In which event handle should I do the actual painting?
3. I'm also trying to implement a function in my Datagridview which makes a cell change it's backcolor when you click on it. I tried doing this by changing the color in the CellClick event but the problem is that the cell doesn't repaint itself until I click on another cell. I have tried using the InvalidateCell method in the CellClick event.
I have also tried doing this in the CellPainting event but then I lose the selection on the Datagridview? How would I implement my own selection code?
4. When I click on a cell my header row repaints itself even though nothing has changed in the header. Is there any way of preventing certain rows to be redrawn. I tried checking if the bounding box of the first row intersected the painting clipping region but that didn't work.
5. Is there any good website that explains the concepts of custom painting, both the basic stuff and the more advanced? Or does anyone have a bit more advanced code that I could have a look at and learn from?
Cheers,
Pedro
1. In which order are the different painting events (RowPrePaint, RowPostPaint, CellPainting, CellFormating, Paint etc) handled? Also is the CellClick event (and similar events) handled before or after the oainting event?
2. I know it's not possible to merge two column headers so I'm trying to paint my own headers. I'm doing this by using the first row as the header and painting on that row. In which event handle should I do the actual painting?
3. I'm also trying to implement a function in my Datagridview which makes a cell change it's backcolor when you click on it. I tried doing this by changing the color in the CellClick event but the problem is that the cell doesn't repaint itself until I click on another cell. I have tried using the InvalidateCell method in the CellClick event.
I have also tried doing this in the CellPainting event but then I lose the selection on the Datagridview? How would I implement my own selection code?
4. When I click on a cell my header row repaints itself even though nothing has changed in the header. Is there any way of preventing certain rows to be redrawn. I tried checking if the bounding box of the first row intersected the painting clipping region but that didn't work.
5. Is there any good website that explains the concepts of custom painting, both the basic stuff and the more advanced? Or does anyone have a bit more advanced code that I could have a look at and learn from?
Cheers,
Pedro