How do I color a cxgrid based on table value?

user763539 picture user763539 · May 21, 2011 · Viewed 32.9k times · Source

I would like all rows where in particular field name 'hello' is present to get colored green. I tried this on customdrawcell:

if abstable1.fieldbyname('somename').asstring = 'Hello' then
  cxgrid.canvas.brush.color:=clGreen

But it wont work... what am I missing here ?

Answer

Sam M picture Sam M · May 22, 2011

Use the OnGetContentStyle event for either individual columns or the grid object. Styles are much easier to work with than messing with the canvas.