delphi - Changing TTextCell background colour at runtime XE4 -


i worked through example posted here starting point: change background of ttextcell in firemonkey tgrid

i have created textcellstyle references image, , working well. when run program cells display background image expected.

from above link, mike sutton (i hope you're reading this, without input!) writes (repeated here make easier):

"you can set each of cells stylelookup properties use it, or set styles stylename textcellstyle have picked automatically every ttextcell."

following on query changing font colours (delphi xe4 firemonkey grid control - styling cells individually), can 1 set background colours dynamically well?

my code on creating cells:

constructor tfinancialcell.create(aowner:tcomponent);  begin   inherited;   stylelookup:='textcellstyle';   styledsettings:=styledsettings-[tstyledsetting.ssstyle,tstyledsetting.ssfontcolor];    textalign:=ttextalign.tatrailing; end; 

this applies image tfinancialcell.

but, per font colour query, image background display when value reached or whatever:

procedure tfinancialcell.applystyling; begin   font.style:=[tfontstyle.fsitalic];    if isnegative     fontcolor:=clared   else     fontcolor:=clagreen;    if isimportant font.style:=[tfontstyle.fsitalic,tfontstyle.fsbold];    if assigned(font.onchanged)     font.onchanged(font);    repaint; end; 

any how appreciated.

thanks mike. had fiddle around bit, got work based on suggestion. added trectangle textcellstyle in stylecontainer, follows:

textcellstyle : tlayout     background: tsubimage         rectangle1: trectangle         rectanimation: trectanimation 

in tfinancialcell.applystyle tried findstyleresource ('background'), returned nil. changed findstyleresource ('rectangle1') , worked great. because looks relevant stylename property (which defaults 'rectangle1' rectangle 1) in object inspector? still not quite seeing wood trees, i'm sure can tell...

the working code:

procedure tfinancialcell.applystyle;  var    t : tfmxobject;  begin   inherited;    t:=findstyleresource('rectangle1');    if (t<>nil) , (t trectangle)   begin      if trectangle(t).fill<>nil      begin        if isnegative        begin         trectangle(t).fill.color:=clared;          repaint;       end;       end;   end;    applystyling; end; 

i tried, separate exercise, put code above in tfinancialcell.applystyling, , worked there, not sure better option, , why?

the summary of understanding of these styles far (please correct/comment necessary):

  1. i have created style called textcellstyle, apply in tfinancialcell.create tfinancialcell class [stylelookup:='textcellstyle'].
  2. when call tfinancialcell.applystyling, able access font , fontcolor properties of tfinancialcell directly, these properties properties of ttextcell.
  3. if want paint background of cells, have explicitly call trectangle component manually added textcellstyle 'style', , access fill etc property there.

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -