Einzelnen Beitrag anzeigen

madtom

Registriert seit: 24. Feb 2005
Ort: Hamburg
115 Beiträge
 
Delphi XE7 Professional
 
#4

AW: StringGrid Zelle einzeln mit If...then färben ?

  Alt 27. Mär 2011, 18:30
Hallo,

hier wäre mal ein Beispiel, wie mann die selektierte Zeile einfärbt: (Quelle: Peter Below (TeamB))

Delphi-Quellcode:
// Coloring the active row of a stringgrid

type
  // required to access protected method InvalidateRow
  TGridCracker = Class( TStringgrid );
  
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
  State: TGridDrawState);
var
  Grid: TStringGrid;
begin
  if gdFixed in State then
    Exit;
  Grid := Sender as TStringGrid;
  if Grid.Row = ARow then
  begin
    with Grid.Canvas.Brush do
    begin
      Color := $C0FFFF;
      Style := bsSolid;
    end;
    Grid.Canvas.FillRect(Rect);
    Grid.Canvas.Font.Color := clBlack;
    Grid.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Grid.Cells[ACol, ARow]);
    Grid.Canvas.Brush := Grid.Brush;
  end;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
  with TGridCracker(Sender as TStringGrid) do
  begin
    InvalidateRow(Row);
    InvalidateRow(ARow);
  end;
end;
Beste Grüße

Thomas
Thomas
  Mit Zitat antworten Zitat