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, 430 downloads since 2020-10-17 

Re: Example of condition color

Dear all,just what i needed thank you all

Re: Example of condition color

derek wrote:

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.

Hello Derek, quick question about this - can this be adopted to the table grid on the report project you helped me out with the other day?  Have the different states to show a color on the grid, example :  green for COMPLETED, yellow for IN PROGRESS and red for WAITING?

Let me know how this can be implemented, please!!!

Re: Example of condition color

Hi,
Try it like this (see attached).
Regards,
Derek.

Post's attachments

Attachment icon gp2k with authorisations fixed.zip 349.5 kb, 274 downloads since 2021-02-16 

8 (edited by gonpublic2k 2021-02-16 00:24:15)

Re: Example of condition color

derek wrote:

Hi,
Try it like this (see attached).
Regards,
Derek.

Very nice Derek, only one thing - what if I wanted to show by using a button for each state I guess, all completed, in progress and waiting?
just like the example you gave above that showed all items out of stock, low stock etc..

I just don't know how to get it done with the combobox part.  Thanks!!!

9 (edited by derek 2021-02-16 12:56:46)

Re: Example of condition color

Hi,
I've added the status as a filter.
However, I've done this as a combobox and not as a separate button for each status because:
1.  It would take up a lot more room so would need a redesign of the form.
2.  It's probably better that your application has a consistency of filter type - I don't think it helps users to have a mix of filter types (sometimes a button, sometimes a combobox etc) if it can possibly be avoided.
Derek.

Post's attachments

Attachment icon gp2k with authorisations 3.zip 349.9 kb, 316 downloads since 2021-02-16 

Re: Example of condition color

derek wrote:

Hi,
I've added the status as a filter.
However, I've done this as a combobox and not as a separate button for each status because:
1.  It would take up a lot more room so would need a redesign of the form.
2.  It's probably better that your application has a consistency of filter type - I don't think it helps users to have a mix of filter types (sometimes a button, sometimes a combobox etc) if it can possibly be avoided.
Derek.

Thank youuuu!!!!!!!!!!!!!!