它可能是基本的,但我有一個時間查找示例代碼的* *,用於根據數據庫中的值更改字符串網格的行顏色Firemonkey。我有一個來自MDB的數據沒有問題,但需要的行是一定的顏色,例如'1'=紅色'2'=綠色等。我知道我必須以某種方式訪問Style元素'OnApplyStyleLookup'?但在什麼階段。我看到了關於改變文字風格和顏色等方面的問題,但我正在挖掘一個洞,試圖進入「背景」元素並應用。任何幫助將不勝感激。 乾杯 理查德...(新手Firemonkey)根據來自數據的值在firemonkey stringgrid上着色單元格背景
9
A
回答
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;
0
這是我的代碼用Delphi柏林的正常工作:
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;
相關問題
- 1. 根據單元格中的值着色單元格
- 2. 根據單元格中的值動態更改單元格的背景顏色
- 3. 根據單元格內的值設置單元格的背景顏色
- 4. 根據單元格值更改背景顏色
- 5. 根據值更改單元格背景顏色onEdit
- 6. 如何根據單元格值更改DataGrid單元格背景顏色
- 7. 根據標題更改表格單元格的背景顏色
- 8. jqGrid根據單元格值在網格中着色整條線
- 9. 根據單元格中的HEX值設置自動顏色背景嗎?
- 10. 根據Jquery的值更改表格中單元格的背景?
- 11. 如何根據單元格中的值在Excel中爲單元格着色?
- 12. Gnuplot:根據數據範圍的着色背景
- 13. 根據值更改表格的背景單元格
- 14. 根據背景顏色清除單元格區域的內容
- 15. 根據數組和顏色映射着色matplotlib的背景
- 16. 如何根據單元格的值對jtable的單元格進行着色
- 17. 如何根據Epplus中的單元格值爲行着色?
- 18. 根據另一個單元格的值爲單元格區域着色?
- 19. 根據另一列的值更改單元格的背景
- 20. 如何根據單元格的值更改DataGridView中行的背景顏色?
- 21. 如何根據值更改單元格的背景
- 22. 如何根據單元格值對所有行進行着色
- 23. 根據選擇和值更改WPF DataGrid單元格的背景顏色
- 24. 根據數值的自動背景顏色
- 25. WPF - 根據CheckBox值更改DataGridTemplateColumn單元格背景
- 26. 根據值更改背景顏色JS
- 27. 我想選擇一系列單元格併爲背景着色
- 28. R Markdown pdf部分顏色的單元格背景(數據欄)
- 29. 根據上一個單元格的值切換單元格值
- 30. jQuery的設置元素的背景顏色根據其值
設置顏色你需要重寫的SetData方法該單元格,但單元類是在StringGrid中硬編碼的。您需要使用具有自定義單元類的普通網格來完成此操作。看看我的文章http://monkeystyler.com/blog/entry/firemonkey-grid-basics-custom-cells-and-columns,瞭解如何做到這一點。 –
非常感謝Mike。你的文章看起來很好記錄。我全職工作(不是編程),所以我知道我將在這個週末做什麼。 –