How do I add text to cells in a DrawGrid? I am using a DrawGrid instead of
a StringGrid because I need to constantly set the font and background colors
for individual cells.
Can anyone help?
--
Mike Sandoval
> How do I add text to cells in a DrawGrid? I am using a DrawGrid instead of
> a StringGrid because I need to constantly set the font and background colors
> for individual cells.
There's no storage facility built into a TDrawGrid, so you'll
have to either use a descendant with such or go back to a
TStringGrid. I would suggest the latter, since you can store
additional info (like the font and color) for each cell and use
the OnDrawCell event handler to render the text with that font
and color info.
Good luck.
Kurt
What I really would suggest is to not waste your time messing around with
making custom grids. aside from the fun of it, everything that you will ever
need to do has been done far better than you ever are going to do it and not for
very much. I don't mean to be against toughing it out for the sake of bragging
to your friends that you made a drawgrid with individually colored cells but
very powerful grids that already do that and much, much more exist for cheap.
The two best that I know of are:
topgrid: (www.objectsight.com)
quantum express grid: I am not sure of the web site.
How do I save, store, the font and color for individual cells? I've tried
many different items, but I always end up changing all the cells either the
same color or same font color. I cannot manage to set individual cell
colors.
Again, thank you.
Kurt Barthelmess (TeamB) <KBarth...@compuserve.com> wrote in message
news:3B033D90...@compuserve.com...
> How do I save, store, the font and color for individual cells?
In a TStringGrid, the text for each cell has an associated
Objects[Col, Row]. You can set this to a TFont with all the
desired properties for that cell. Then in the OnDrawCell event
handler, plug that TFont object into your Canvas and draw the
text.
Good luck.
Kurt
Thank you for all your help. Below is what I have ended up with. I was
hoping to set the StringGrid1.Font.Color, so that I could use the
Cells[ACol, ARow] feature of the StringGrid; however, I can only set the
Canvas.Font.Color to get the result I am looking for. Am I doing something
wrong?
The following snippet of code is executed OnDrawCell:
k := ((ACol div 2)*32 + (ACol mod 2) + 1) + ARow*2;
case (k mod 2) of {will replace (k mod 2) with state of k for
appropriate canvas and font color later}
0: begin
StringGrid1.Canvas.Brush.Color := clRed;
StringGrid1.Canvas.FillRect(Rect);
StringGrid1.Canvas.Font.Color := clBlue;
StringGrid1.Canvas.TextOut(Rect.Left + Font.Size, Rect.Top + 4,
IntToStr(k));
end;
1: begin
StringGrid1.Canvas.Brush.Color := clBlue;
StringGrid1.Canvas.FillRect(Rect);
StringGrid1.Canvas.Font.Color := clYellow;
StringGrid1.Canvas.TextOut(Rect.Left + Font.Size, Rect.Top + 4,
IntToStr(k));
end;
end;
Thanks,
Mike
Kurt Barthelmess (TeamB) <KBarth...@compuserve.com> wrote in message
news:3B04952A...@compuserve.com...
> Thank you for all your help. Below is what I have ended up with. I was
> hoping to set the StringGrid1.Font.Color, so that I could use the
> Cells[ACol, ARow] feature of the StringGrid; however, I can only set the
> Canvas.Font.Color to get the result I am looking for. Am I doing something
> wrong?
I don't see anything with what you are doing. You need to set
Canvas.Font.Color because Delphi has already done whatever
initialization it is going to do and won't check it again. But I
don't see what that has to do with not being able to use
Cells[ACol, ARow].
Good luck.
Kurt