2017-01-17 9 views
0

特定の列の値に基づいて行全体をペイントする方法はありますか?私のコラム状態が値が黄色であることを行全体を再描画されている場合TStringgrid firemonkeyの条件付きで行の色を変更します

ID | NAME | DATE  | STATE 
1  X  2017-01-01  TRUE   --whole row need to be yellow 
2  Y  2017-01-01  FALSE   --default color (no change) 

: は、私は4つの列にTStringGridを持っています。

私はこれを試してみましたが、それは唯一の状態列に動作します場合には代わりに「3」のconstの値を使用するように

procedure TTNarudzbenice.grSomeNameDrawColumnCell(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;const Row:Integer; const Value: TValue; const State: TGridDrawStates); 
var 
    aRowColor: TBrush; 
begin 

    aRowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha); 
    //----- 
    if Value.ToString = 'TRUE' then 
    begin 
    aRowColor.Color := TAlphaColors.Yellow; 

    Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor); 

    Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State); 

end; 

    aRowColor.free; 

end; 

答えて

3

だけで簡単に調節

procedure TTNarudzbenice.grSomeNameDrawColumnCell(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;const Row:Integer; const Value: TValue; const State: TGridDrawStates); 
var 
    aRowColor: TBrush; 
begin 

    aRowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha); 
    //----- 
    if (Sender as TStringGrid).Cells[ 3, Row ] = 'TRUE' then //// This line changed 
    begin 
    aRowColor.Color := TAlphaColors.Yellow; 

    Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor); 

    Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State); 

    end; 
    aRowColor.free; 

end; 

より良いです列が変わります。要点は、このルーチンがすべてのセルに対して呼び出されることですが、現在描画されているセルに関係なく、4番目の列の値を比較したいだけです。

関連する問題