Oleh: antoniusrc | 22 Mei 2008

How to coloring a stinggrid cell?

Location of colored cell:

private
ColorCol, ColorRow: integer;

Set colored cell column and row with Button1, and force stringgrid to repaint:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ColorCol := Col;
  ColorRow := Row;
  StringGrid1.Repaint;
end;

Color delphi stringgrid cell in OnDrawCell event handler:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;Rect: TRect; State: TGridDrawState);
var
  S: string;
begin
  if (ACol = ColorCol) and (ARow = ColorRow) then begin
   StringGrid1.Canvas.Brush.Color := clYellow;
   StringGrid1.Canvas.FillRect(Rect);
   S := StringGrid1.Cells[ACol, ARow];
   StringGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, S);
  end;
end;

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Kategori

%d blogger menyukai ini: