Draw lines over a TStringGrid (Views: 100)


I have a TStringGrid with objects put in big coloumns of 4 normal columns. How can I draw a black line from top to bottom over the gray line that the grid itself draws?


Handle the OnDrawCell event for the grid. If the cell you are asked to draw is in the column in question you draw the part of the line that crosses the cell:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
  if (aCol = 1) and not (gdFixed in State) then
    with (sender as tstringgrid).canvas do
      Pen.Color := clBlack;
      Pen.Width := 2;
      Pen.Style := psSolid;
      MoveTo(rect.right - 1, rect.top);
      Lineto(rect.right - 1, rect.bottom);

<< Back to main page