Jump to content


Photo

color cell in column 1 based upon value in column 2


  • Please log in to reply
4 replies to this topic

#1 nosx

nosx
  • Members
  • 11 posts

Posted 07 August 2014 - 10:20 PM

I am using the following code to set the font color of a cell based upon it's value and this works fine. What I need to do now is change the color of a cell in ANOTHER column based upon this value as well. How would I do that ?

For example, Column 2 can contain two different values (Yes, No). What I want to do is alter the code below to change the TextColor of the cells in Column 1 & Column 2 both based upon the value in Column 2. What needs to change in the code below to make this possible?

Here is the code I am using to change the font color of a cell based upon it's value.

procedure TForm1.NextDBGrid1CellFormating(Sender: TObject; ACol,
ARow: Integer; Value: WideString; var TextColor: TColor;
var FontStyle: TFontStyles; CellState: TCellState);
begin
if (ACol = 2) then

if value = 'No' then
begin
TextColor := clRed;
end;
end;

Please note, The above question may imply that I want to just change the font color for all the cells in a row and this is not what I want to do. All I want to do is change the font color of the cells in columns 1 & 2 ONLY, Any other cells in the row should not be affected by this code.

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,021 posts
  • Gender:Male

Posted 12 August 2014 - 10:08 PM

Hi,

You need to use event for ACol = 1 and ACol = 2 and then inspect value from Columns[2].Field.AsString = 'No'

Something like this:

if ACol = 1 then
If NextDBGrid1.Columns[2].Field.DisplayText = 'No' then
begin
  TextColor := clRed;
end;

I hope that this helps.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 Bagong

Bagong
  • Members
  • 32 posts

Posted 15 March 2021 - 03:50 AM

Can it be implemented on nextdbgrid v6??



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,021 posts
  • Gender:Male

Posted 15 March 2021 - 12:14 PM

Hello,

 

There is an event for Column (you need to select the column) and the you have an event for styling cell text. It have very much the same var parameters.

 

I hope that this helps.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 Bagong

Bagong
  • Members
  • 32 posts

Posted 20 March 2021 - 12:04 PM

Hello,

 

There is an event for Column (you need to select the column) and the you have an event for styling cell text. It have very much the same var parameters.

 

I hope that this helps.

 

 

could you please make an example code






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users