根据数据中的值在firemonkey stringgrid上为单元格背景着色 [英] Coloring cell background on firemonkey stringgrid according to value from data

查看:109
本文介绍了根据数据中的值在firemonkey stringgrid上为单元格背景着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是基本的,但是我有一次 * *的时间查找示例代码,以根据Firemonkey中数据库的值更改stringgrid的行颜色。我有来自MDB的数据,没有问题,但需要将行设置为某些颜色,例如‘1’=红色‘2’=绿色等。我知道我必须以某种方式访问​​'OnApplyStyleLookup'的Style元素吗?但是在什么阶段我已经看到了有关更改文字样式和颜色等问题,但是我为自己寻求一个背景元素并应用它正在挖一个坑。任何帮助将不胜感激。
干杯
理查德...(Firemonkey的新手)

It may be basic but I'm have a ** of a time finding sample code to change a row color of a stringgrid based on a value from a database in Firemonkey. I have data coming from a MDB no problems but need the row to be certain colors for ie '1' = red '2' = green etc. I know I have to access the Style elements somehow 'OnApplyStyleLookup'? but at what stage. I have seen questions on changing text style and colour etc but I am digging a hole for myself trying to get to the 'background' element and applying. Any help would be greatly appreciated. Cheers Richard ...(newbie to Firemonkey)

推荐答案

{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;

这篇关于根据数据中的值在firemonkey stringgrid上为单元格背景着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆