0

I have two grids:

in one form and compare between two value
I need to change the color of the column in the grid when the two values are not equal

  TotalYear:=0 ;
  while not (mTblDetail.eof) do
  begin
       TotalYear:=TotalMonth +mTblDetail.FieldByName('Target_').AsFloat;
       mTblDetail.Next;
  end;
  TotalMonth:=0;
  while not(DataSet.Eof) do
  begin
      TotalMonth:=TotalMonth+DataSet.FieldByName('Target_').AsFloat;
      DataSet.Next;
  end;


I need to compare the two values and change the color

if(TotalYear<>TotalMonth) then


I tried to use this :

 DataSet.Columns[8].Color:= clRed

but is displays an error "Not Accepted". How Can change the color of a column of a Tcxgrid?

whosrdaddy
  • 11,720
  • 4
  • 50
  • 99
user3420275
  • 27
  • 2
  • 12
  • use `OnDrawColumnCell` event `if (Column.Field.FieldName = 'MyFieldName') and ...Field Value ...(TotalYear<>TotalMonth) then Column.Color := clRed;` – Val Marinov Oct 04 '15 at 09:30
  • Are those while loops your real code? For one thing, you shouldn't need two while loops to increment two variables, you can do them in the same loop. Another thing is that each time around the first loop, you overwrite the value of TotalValue (because its new value isn't based on its previous one). If you want help, please post real code. Btw, Delphi doesn't support HTML mark-up in its source code, which is why "DataSet.Columns[8].Color:= clRed
    " won't compile
    – MartynA Oct 04 '15 at 09:37
  • Wow really? Then see this http://stackoverflow.com/questions/6078715/how-do-i-color-a-cxgrid-based-on-table-value – Val Marinov Oct 04 '15 at 09:40
  • i Can't find property color ? whet's error? – user3420275 Oct 04 '15 at 09:43
  • 1
    @user3420275, Datasets don't have any knowledge of UI elements, so colouring is the responsability of the component that displays the dataset, in your case the tcxgrid. Anyway, you should ask the component vendor, or do a search on their knowledgebase, [like I did](https://www.devexpress.com/Support/Center/Question/Details/A329). – whosrdaddy Oct 04 '15 at 11:02

1 Answers1

2

Coloring in cxGrids is best done via cxStyles. Drop a TcxStyleRepository on the form and add some styles. You can assign them to the View.Styles.* properties or via events like OnGetContentStyle. I'm sure the online help contains an overview with screenshots and examples.

Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83