2017-01-17 1 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) 

상태 내 열 경우 진정한 가치 을했다 노란색으로 전체 행을 다시 칠.

나는 이것을 시도했지만 그것은 단지 열 상태에 작동합니다 경우 대신에 '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 번째 열의 값을 비교하려는 것입니다.