お知らせ

電子会議

ライブラリ

FDelphi サイト全文検索

Delphi FAQ一覧

サンプル蔵



FDelphi FAQ
15番会議室「FAQ編纂委員会」に寄せられた「よくある質問の答え」

[Q]
StringGridで例えばCellに入力されている値によって色を 変えたいが、どのようにすれば良いのでしょう?

[A]
OnDrawCellイベントにCellの内容に従ってCellを塗りつぶす
コードを記述します。
さらにCellの内容が書き換わったら再描画を行うように、
OnSetEditTextイベントに再描画を促すコードを記述します。
[例]
例えば、StringGridの1列目がブランクだったらその行の
色をclAquaにするコードです。

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  Rect: TRect; State: TGridDrawState);
begin
     If (StringGrid1.Cells[1,Row] = '') And Not (gdFixed In State) Then
        With StringGrid1.Canvas Do
        Begin
           Brush.Color := clAqua;
           FillRect(Rect);
           TextOut(Rect.Left + 2, Rect.Top + 2, StringGrid1.Cells[Col, Row]);
        End;
end;

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
  ARow: Longint; const Value: string);
var
   ARect : TRect;
begin
    If (ACol = 1) Then
    Begin
       ARect := StringGrid1.CellRect(ACol, ARow);
       ARect.Right := StringGrid1.Width;
       InvalidateRect(StringGrid1.Handle, @ARect, True);
    End;
end;


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum FDELPHIに寄せられる質問の中から、よくある質問への回答を FDELPHIのメンバーがまとめたものです。 したがって、これらの回答はボーランド株式会社がサポートする公式のものではなく、掲示されている内容についての問い合わせは受けられない場合があります。

Copyright 1996-1998 Delphi Users' ForumFAQ編纂委員会