Einzelnen Beitrag anzeigen

hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.276 Beiträge
 
Delphi 10.4 Sydney
 
#6

Re: Stringgrid Zelle färben beim Editieren

  Alt 13. Okt 2008, 19:59
Hallo,

mal ein kleines Bsp.


Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TForm1 = class(TForm)
    Grid: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure GridDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  iCol : Integer;
  iRow : Integer;
begin
  for iCol:= 0 to Grid.ColCount-1 do
  begin
    for iRow:= 0 to Grid.RowCount-1 do
    begin
      Grid.Cells[iCol,iRow]:= IntToStr(iCol);
    end;
  end;
end;

procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if Grid.Cells[ACol,ARow]='0then
  begin
    Grid.Canvas.Brush.Color:= clRed;
    Grid.Canvas.FillRect(Rect);
  end
  else
  begin
    Grid.Canvas.Brush.Color:= clBlue;
    Grid.Canvas.FillRect(Rect);
  end;

  Inc(Rect.Left,2);
  DrawText(Grid.Canvas.Handle, PChar(Grid.Cells[ACol,ARow]),
    Length(Grid.Cells[ACol,ARow]), Rect,
    DT_END_ELLIPSIS or DT_NOPREFIX);
end;

Heiko
Heiko
  Mit Zitat antworten Zitat