Sign in Join
Wiki copytemporary

Revision 1 of 2, by Jwdietrich on 4-5-2023. The page as it is now.

TDrawGrid

TDrawGrid is a component on the Additional tab of the Component Palette. A DrawGrid provides a tabular display of graphical information. The developer is responsible for providing the code for drawing.

Therefore, unlike other grid types, TDrawGrid requires implementing the following properties:

The following simple example shows how to use OnDrawCell:

pascal
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  aRect: TRect; aState: TGridDrawState);
var
  theCanvas: TCanvas;
begin
  theCanvas := TDrawGrid(Sender).Canvas;
  if odd(aRow) then
  begin
    if odd(aCol) then
      theCanvas.Brush.Color := clRed
    else
      theCanvas.Brush.Color := clGreen;
  end
  else
  begin
    if odd(aCol) then
      theCanvas.Brush.Color := clBlue
    else
      theCanvas.Brush.Color := clYellow;
  end;
  theCanvas.FillRect(aRect);
end;

The demonstration code in this example fills the content of the cells with different colours, depending on whether the rows or columns are even or odd:

<figure> <img src="TDrawGridExample.png" title="TDrawGridExample.png" /> <figcaption>TDrawGridExample.png</figcaption> </figure>

See also


From the Free Pascal wiki, page "TDrawGrid", as it stood on 2023-04-05 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.