Draw lines on merged cells

I have a grid with many merged cells. The merged cells represent processes in a timeline like the tplanner does. For some reasons I cannot use the tplanner for that. So I went with the grid and it works great.

Only problem I have is, that I'd like to have lines drawed in the grid at several points on the time lime.

For example the rows of the grid represent hours of a day and there are merged cells over several hours, I want to draw lines for each hour through the merged cells.
I allready got it working by manually drawing the lines in the OnPainted event. The drawback is, that the lines are drawn over the text in the cells. So I need to draw the lines prior the output of the text.

I probably could do it in the OnDrawCell event, but I do not know how to get the coordinates where the lines should be drawn in the OnDrawCell event for the current cell.

Any hints, how I can do this?

You can get the pixel coordinates of a cell in the grid with


grid.CellRect(Col,Row: integer): TRect;

Thanks for that.

I tried to use OnDrawCell and OnCustomCellDraw to draw lines.

OnCustomCellDraw could work. My problem is, that the text of the cells that is assigned to cells[col, row] is painted prior to OnCustomCellDraw and when I draw the lines in OnCustomCellDraw it covers parts of the text. It's the same like when I draw lines in OnPainted.
So I need some way to first paint the lines and then paint the text. I cvannot use textout, because that does not work with the HTML tags. Is there a way to do some drawing "under" the text (first draw and then write the text to the cell)?


I made a screenprint that shows how it should look like except the horizontal lines in the merged cells should be under the text.

http://img908.imageshack.us/img908/8475/mxqUP2.jpg

You can see, that I use gridrows with 1pixel height and merge as many rows together to get the height to represent the length of a task. So the beginning and end of the merged cells are not coresponding to the first column that displays the timeline, but I need lines through all columns every hour that goes above the backgroundcolor of the cell but under the text of the cell.

I hope my description is clear enough.


With "under the text" I mean "behind the text".

Not always easy to find the right english word ;-)

OnCustomCellBkgDraw is the event for customizing background of the cell.

Thank you so much. That worked great for me.