Topic: Row colored by column content

Hello Dimitri

By being inspired from your script :

Form1.TableGrid1.Cell[0, 0].Color:= clRed;
Form1.TableGrid1.Cell[0, 0].TextColor:= clGreen;

In a column titled, how could I get a different color by theme.
Example :

I have a column titled Gender (for books)
I would have all books Fantasy colored blue, all Thrillers red, all novels green, and so on.
By the way, how to have all the different row colored by theme ?

I don't guess what will be the script.
All I have tried give up error.

Thanks for you help

Yann Yvinec

Re: Row colored by column content

Hello,


You can do it in the beta version 1.44
https://www.dropbox.com/s/2phoggh5kfu88 … 4.zip?dl=0


Project example
http://myvisualdatabase.com/forum/misc. … download=1


code:

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;
Dmitry.

Re: Row colored by column content

Hello Dimitri,

I've downloaded MVD 1.44 and it works fine

Thanks again

Jean B.

Re: Row colored by column content

Congratulation for the software is very practical.

I have seen the example, but how you can color a row complete, based on the value of a non-visible column in the table grid?

Thank you.

Re: Row colored by column content

rrg33l


procedure Form1_GridEmployees_OnChange (Sender: string);
var
   i,c: integer;
   k, q: integer;
begin
     Form1.GridEmployees.Columns[3].Visible := False; // hide column
     c := Form1.GridEmployees.RowCount - 1;
     q := Form1.GridEmployees.Columns.Count - 1;
     for i := 0 to c do
     begin
         if Form1.GridEmployees.Cells[3,i] = 'Yes' then
            for k := 0 to q do Form1.GridEmployees.Cell[k,i].Color := clRed;
         if Form1.GridEmployees.Cells[3,i] = 'No' then
            for k := 0 to q do Form1.GridEmployees.Cell[k,i].Color := clGreen;
     end;
end;

Also i made example project for you, here you can download

Post's attachments

Attachment icon Color Grid with hide column.zip 5.05 kb, 673 downloads since 2014-09-30 

Dmitry.

Re: Row colored by column content

Thanks for you help again.

Re: Row colored by column content

Another question on same topic, is it possible to change colours depending on cell with 2 variables?

example:


Status                     Count

Ready                     40                  ---------> above 5= green, under 5=Red
Defect                     3                    ---------> 0= green, from 1=text red, above 2= background red
Unavailable             2                   ---------> 0= green, from 1=text red, above 5= background red


Can I change the colours depending of the count for each status independently but in same tablegrid?

I remember also having seen a topic about changing the colour depending on time... will try to retrieve it.

Re: Row colored by column content

Maybe the InRange Function is what you are looking for

http://delphi.about.com/library/rtl/blr … ndling.htm

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Row colored by column content

Thanks for the link, but I am not a programmer, this is why I am using MVDB big_smile 

What I am looking for is an example to be able to understand how I could implement it in my project. The only example I know does not make any difference on the column "status", it just check the value in column "Count".

I will try to sort it out but I guess I will have to write a condition for each status + each way of counting...

Re: Row colored by column content

OK, understood smile

Question : do you have a table with multiples rows and the tablegrids adds together the 3 status to give you total count of each, or do you have only 3 rows in that table with a total number for each ?

In other words, is the value displayed in the tablegrid calculated before beeing displayed ?

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Row colored by column content

I have a simple grid which displays the result of the following query:

SELECT *
FROM
(
   SELECT 'Ready'  as "Status", COUNT(id)  AS Count FROM computers where id_status="3"
  UNION ALL
  SELECT 'Defect'  as "Status", COUNT(id)  AS Count FROM computers where id_status="2"
   UNION ALL
  SELECT 'To be Restaged'  as "Status", COUNT(id)  AS Count FROM computers where id_status="4"

) temp

And it is displayed as shown in the attached screenshot.

The colours are not yet established, it is under construction wink

Post's attachments

Attachment icon image7.png 2.65 kb, 343 downloads since 2015-03-05 

Re: Row colored by column content

By two variables do you mean for example :


if 0 then color is green
if between 1 and 5 color is orange
if 6 or greater then color is red ?


Is it the between statment that causes you problem ?


If yes (and I say if because it would not be the first time I answer a question you did not ask wink), then you shoud try the in [x..y] statment like this :

if Form1.TableGrid1.Cells[1,i] in [0..9]) then
...instruction...
if Form1.TableGrid1.Cells[1,i] in [10..19]) then
...instruction...
if Form1.TableGrid1.Cells[1,i]  >=20 then
...instruction...

Hope I got it right this time wink


Have a good day


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Row colored by column content

Actually, I would like to have a condition on the text as well so the colour would not apply on all rows with a number in the set colour range....

so the 2 variables are

cell 1 (Status) and cell 2 (Count)

in cell 1 I can have different text : Ready, Defect, To restage

in cell 2 I can have different numbers : from 0 to n

but I do not want cell 2 of each row being colored the same way on each row!

If I use the current known scripts, all row change their colour when the count reaches the defined threshold which is useless in my project. I need different colours for different information, a count of 2 Ready would be Red whereas a count of 2 Defect would be Green and a count of 2 To restage would be Orange, you see!