基本的なことかもしれませんが、Firemonkey のデータベースの値に基づいて stringgrid の行の色を変更するサンプル コードを* * 探しています。MDB からのデータは問題ありませんが、「1」= 赤、「2」= 緑など、行を特定の色にする必要があります。何らかの方法で「OnApplyStyleLookup」でスタイル要素にアクセスする必要があることはわかっています。しかし、どの段階で。テキストのスタイルや色などの変更に関する質問を見てきましたが、「背景」要素にアクセスして適用しようとして自分で穴を掘っています。どんな助けでも大歓迎です。乾杯リチャード ...(Firemonkey の初心者)
6772 次
2 に答える
4
{OnDrawColumnCell event}
procedure OnDrawColumnCell(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var
RowColor : TBrush;
begin
RowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);
{you can check for values and then set the color you want}
if Value.ToString = 'red' then
RowColor.Color := TAlphaColors.Red;
Canvas.FillRect(Bounds, 0, 0, [], 1, RowColor);
{ perform default drawing }
TGrid(Sender).DefaultDrawColumnCell(Canvas, Column, Bounds, Row,
Value, State);
end;
于 2014-08-22T17:08:11.520 に答える
0
これは、正常に動作する Delphi Berlin での私のコードです。
var
aRowColor: TBrush;
begin
//it's better to write this line into create
aRowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);
//-----
grid.DefaultDrawing := False;
if (myTbl.RcrdDataCount > 0) and (Row < myTbl.RcrdDataCount) then begin
if myTbl.RcrdDataItems[Row].State = TStateDeleted then begin
aRowColor.Color := TAlphaColors.Red;
end
else begin
aRowColor.Color := TAlphaColors.Gray;
end;
Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor);
Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
end;
//it's better to write this line into destroy
aRowColor.free;
//-----
end;
于 2016-10-06T10:12:32.623 に答える