Topic: Example of condition color

Hi MVD team, it's possible to add like a minimul stock and in the table grid to show colors?

if tis reach a number seted te be red
if it biger than the number above to be green
and if it's equal to the number t be yellow

Re: Example of condition color

Hello popcornInicusor

You could adapt thoses siippets to your projets.

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] = 'Yes' then Form1.TableGrid1.Cell[3,i].Color := clRed;
         if Form1.TableGrid1.Cells[3,i] = 'No' then Form1.TableGrid1.Cell[3,i].Color := clGreen;
    end;
end;

Same ways with dates (< Date and Date + 1) :

procedure Form1_TableGrid1_OnChange (Sender: TObject);
var
   i,c: integer;
begin
   Form1.TableGrid1.BeginUpdate;
   c := Form1.TableGrid1.RowCount - 1;
   for i := 0 to c do
   begin
      if StrToDateTime(Form1.TableGrid1.Cells[4,i]) < Date then Form1.TableGrid1.Cell[4,i].Color := $00FF80FF;
      if StrToDateTime(Form1.TableGrid1.Cells[4,i]) = Date+1  then Form1.TableGrid1.Cell[4,i].Color := clGreen;
   end;
   Form1.TableGrid1.EndUpdate;
end;

JB

3 (edited by CDB 2020-10-17 07:56:27)

Re: Example of condition color

I can offer you this, the rows change colour depending on criteria - basically just another way of doing what JB has written above.   If your code can use a SELECT statement you'd be able to make the code below more compact.


procedure frmMain_tgOrders_OnChange (Sender: TObject);
CONST
    DATE_ORD = 5; DATE_PO = 7; DATE_REQ = 8; ORD_QTY = 9; ORDER_REC = 10; DUE = 11;
var
row, column, rowcnt, colcnt: integer;
begin

   rowcnt := frmMain.tgOrders.RowCount -1;
   colcnt := frmMain.tgOrders.Columns.Count -1;

   for row := 0 to rowcnt do
   begin
       if frmMain.tgOrders.Cells[DUE,row] = '0' then     //Complete order received colour red/pink
       begin
           for column := 0 to colcnt do
           begin
               frmMain.tgOrders.Cell[column,row].Color := $00BDA8FD;
           end;
      end
      else
    
      {Part order received   colour Blue}
          if (frmMain.tgOrders.Cells[DUE,row] < frmMain.tgOrders.Cells[ORD_QTY,row])    then     //Complete order recieved
           begin
               for column := 0 to colcnt do
               begin                                       //light blue
                   frmMain.tgOrders.Cell[column,row].Color :=$00FFFFA8; // interesting brown $0065AACD;
               end;
          end     
      else
     

        {Quote pending colour green}
          if (frmMain.tgOrders.Cells[DATE_REQ,row] <> '') AND (frmMain.tgOrders.Cells[DATE_PO,row] ='') then
           begin
               for column := 0 to colcnt do
               begin                                          //light green
                   frmMain.tgOrders.Cell[column,row].Color := $00B4F2B6;
               end;
          end    
      else   

    {To be ordered colour yellow}
    if  ((frmMain.tgOrders.Cells[DATE_ORD,row] = '')AND (frmMain.tgOrders.Cells[DATE_PO,row] ='') AND (frmMain.tgOrders.Cells[DATE_REQ,row]= '')) then
       begin
           for column := 0 to colcnt do
           begin                                          //light yellow
               frmMain.tgOrders.Cell[column,row].Color := $0080FFFF;
           end;
      end;

   end;
 
end;
On a clear disk you can seek forever

4 (edited by derek 2020-10-17 14:45:48)

Re: Example of condition color

Hi Popcornelnicusor, CDB.  Salut Jean,
Hope you're all keeping well.
Another option (no script needed) is to use a calculated field to hold a 'stock status' flag (please see attachment 'conditional grid 1') which also gives the ability to sort and filter by 'stock status' which might be of use.
Or you could combine it with Jean and CDB's suggestions and colour the  'stock status' flag (please see attachment 'conditional grid 2').
Regards,
Derek.

Post's attachments

Attachment icon condtional grid.zip 677.2 kb, 50 downloads since 2020-10-17 

Re: Example of condition color

Dear all,just what i needed thank you all