2009. június 16., kedd

How to remove the focus rectangle and highlighted cell in a read-only TDBGrid


Problem/Question/Abstract:

How can I get rid of highlighting, focus rectangle etc. in a TDBGrid. I want the grid to display information only - without the user seeing highlighted cells etc. If I disable the grid, the user cannot use the scrollbars.

Answer:

Try this. You can adjust it to your needs:


procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if not (gdFixed in State) then
    StringGrid1.Canvas.Brush.Color := clWindow;
  StringGrid1.Canvas.FillRect(Rect);
  InflateRect(Rect, -1, -1); {resize so text is not on line}
  DrawText(StringGrid1.Canvas.Handle, PChar(StringGrid1.Cells[ACol, ARow]), -1,
    Rect, DT_SINGLELINE or DT_VCENTER or DT_LEFT);
end;

Nincsenek megjegyzések:

Megjegyzés küldése