1 (edited by lejoso 2023-05-29 13:46:34)

Topic: Color cell from 2 conditions

Hello everybody.
In my database I have recorded the measurements, in centimeters, of the waist circumferences of both men and women. I need a procedure that makes the tablegrid's waist circumference cell turn yellow when men's is greater than 102cm and women's is greater than 88cm.

I tried this code but without success:

procedure frmStart_TableGrid1_OnChange (Sender: TObject);

   i,c: INTEGER;

    c := frmStart.TableGrid1.RowCount - 1;
     for i := 0 to c do

        IF (frmstart.TableGrid1.Cells[4,i] = 'MASCULINO') AND (StrToInt(frmStart.TableGrid1.Cells[52,i]) > 102) Then frmStart.TableGrid1.cell[52,i].Color := clYellow
        ELSE frmStart.TableGrid1.cell[52,i].Color := clWhite;

Is it possible to do that?

Re: Color cell from 2 conditions

This is working code.

The problem seems to be something else.
Column numbering does not start from 1, extra spaces in the text ...
It's hard to say without seeing an example.

Re: Color cell from 2 conditions

Hello sparrow

Thanks for answering.

I managed to get the cell colored (it wasn't column 52, but 53) but those below 102 are also being selected, especially fractions ("98.2", "88.7", "99"... ), and some greater than 102 are not selected ("112.1", 106..). It must be some detail I haven't figured out yet.

Post's attachments

Attachment icon Column Color.jpg 34.84 kb, 28 downloads since 2023-05-30 

Re: Color cell from 2 conditions

If you have cell values ("98.2", "88.7", "99"...) you should use StrToFloat instead of StrToInt.
I can't offer any more advice without seeing your example.