Topic: Color on value in table grid

Hello guys,

i,m having a project about spare parts database,i have a question and it whould be great if you could give me an example.
the idea is to flash with color in the cell of the table grid:green if cel value is >1,turn yellow if cell value is cell value is =1,and turn red if cell value is =0 (just like excel conditional formatting).Thanks

Re: Color on value in table grid

Hello popcorninicusor

I use this procedure to color cells matching a value (here when managing a books collection).
It wil be easy to adapt it to your needs.

procedure Form1_TableGrid1_OnChange (Sender: string);
var     i,c: integer;
begin
    c := Form1.TableGrid1.RowCount - 1;
    for i := 0 to c do
    begin
         if Form1.TableGrid1.Cells[3,i] = 'Fantasy' then Form1.TableGrid1.Cell[3,i].Color := clBlue;
         if Form1.TableGrid1.Cells[3,i] = 'Thrillers' then Form1.TableGrid1.Cell[3,i].Color := clRed;
    end;
end;

You can also give RGB code of this colour  :

Form1.TableGrid1.Cells[3,i] = 'Thrillers' then Form1.TableGrid1.Cell[3,i].Color := RGBToColor(248, 248, 248);


Hope this helps you

JB

Re: Color on value in table grid

Dear Jen,
many thanks i will give it a try.(novice)

Re: Color on value in table grid

could you give me a short example it will be much easy to me ...thanks!

Re: Color on value in table grid

Hello

You have to replace my values (thrillers, fantasy) by your own (>1,=1,=0).

JB

6 (edited by derek 2018-01-14 19:49:21)

Re: Color on value in table grid

Hello Popcorninicusor, Jean,
I had an old example that was pretty close so I've modified it and attached it - maybe this will help.
This doesn't do 'flashing' cell colours (not entirely sure how you would actually code for that) but, in my experience, it tends to be quite annoying after the first couple of minutes anyway!
Dont worry about being a novice - we've all been there - LOL!
Regards,
Derek.

Post's attachments

Attachment icon parts.zip 338.72 kb, 561 downloads since 2018-01-14 

Re: Color on value in table grid

Thank you very much guys i realy appreciated