2017-01-17 72 views
0

如何根據特定列中的某個值繪製整行? 我已經TStringGrid有四列: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) 

如果我的專欄狀態已經值重繪整排爲黃色。

我都試過,但它只能在列狀態:萬一

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; 

的更好,而不是使用「3」常量的值該列發生變化。重點是這個例程將被調用所有的單元格,但你只想比較第四列的值,而不管當前正在繪製哪個單元格。

相關問題