Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread OnCellUpdate
Wed, Feb 3 2016 11:59 AMPermanent Link

Uli Becker

I want the first two columns of a TGrid to have a gray background color
and tried the OnCellUpdate event for that.
That works as expected except when the row is selected. Then the cell
should not be colored.

I found this in a post from last year:

<<
b) The OnCellUpdate event handler may have to do some interface state
comparisons to determine whether or not to color the cell.  For example,
you
may not want to color the cell when it's "selected".
>>

How can I do that?

Thanks Uli
Wed, Feb 3 2016 2:09 PMPermanent Link

Raul

Team Elevate Team Elevate

On 2/3/2016 11:59 AM, Uli Becker wrote:
> I want the first two columns of a TGrid to have a gray background color
> and tried the OnCellUpdate event for that.
> That works as expected except when the row is selected. Then the cell
> should not be colored.
> How can I do that?

how about something like this as an example: (you need to call same
event for first 2 columns) :

procedure TForm1.GridColumn2CellUpdate(Sender: TObject; ACell: TGridCell);
begin
   if ACell.Index = Grid1.RowIndex then
      ACell.Background.Fill.Color := clTransparent
   else
      ACell.Background.Fill.Color := clLightGray;
end;


Raul
Wed, Feb 3 2016 2:34 PMPermanent Link

Uli Becker

Raul,

simple and great idea.

Thanks Uli
Wed, Feb 3 2016 2:38 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

<< How can I do that? >>

Use something like this:

procedure TForm1.GridColumn5CellUpdate(Sender: TObject; ACell: TGridCell);
begin
  if SameText(ACell.InterfaceState,NORMAL_STATE_NAME) then  << This is the key test !
     begin
     if SameText(ACell.Data,'110') then
        begin
        ACell.Font.Color:=clWhite;
        ACell.Background.Fill.Color:=clElevateRed;
        end
     else if SameText(ACell.Data,'144') then
        begin
        ACell.Font.Color:=clWhite;
        ACell.Background.Fill.Color:=clElevateOrange;
        end
     else if SameText(ACell.Data,'44') then
        begin
        ACell.Font.Color:=clWhite;
        ACell.Background.Fill.Color:=clElevateGreen;
        end
     else
        ACell.RefreshInterface;
     end;
end;

The RefreshInterface call is necessary to ensure that the cell is displayed in a "normal" fashion if it was previously given a different background color due to the custom cell updates that are being done.

You can test the interface state of a cell to determine if it's selected, focused, etc.  The state names are in the WebCtrls unit at the top in the const section:

  { State names }

  NONE_STATE_NAME = 'None';  // Used for refreshing interface states (is a non-operation)
  NORMAL_STATE_NAME = 'Normal';
  DISABLED_STATE_NAME = 'Disabled';
  HOT_STATE_NAME = 'Hot';
  FOCUSED_STATE_NAME = 'Focused';
  PUSHED_STATE_NAME = 'Pushed';
  MINIMIZED_STATE_NAME = 'Minimized';
  READONLY_STATE_NAME = 'ReadOnly';
  ACTIVE_STATE_NAME = 'Active';
  EMPTY_STATE_NAME = 'Empty';
  SELECTED_STATE_NAME = 'Selected';
  BOTH_STATE_NAME = 'Both';
  HIDDEN_STATE_NAME = 'Hidden';
  ERROR_STATE_NAME = 'Error';

Not all of these apply to grid cells, of course.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Feb 3 2016 2:44 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi Tim,

How about following? Where can I (if I can) put "ACell.RefreshInterface"?

if (ACell.Index mod 2) = 0 then
 begin
   ACell.Font.Size := 12;
   ACell.Font.Color := clBlack;
   ACell.Background.Fill.Color := clWhite;
 end
 else
 begin
     ACell.Font.Size := 12;
     ACell.Font.Color := clBlack;
     ACell.Background.Fill.Color:=clAliceBlue;
 end;

Thanks Smile

Regards,
Hüseyin


On 03-02-2016 20:38, Tim Young [Elevate Software] wrote:
> Uli,
>
> << How can I do that? >>
>
> Use something like this:
>
> procedure TForm1.GridColumn5CellUpdate(Sender: TObject; ACell: TGridCell);
> begin
>     if SameText(ACell.InterfaceState,NORMAL_STATE_NAME) then  << This is the key test !
>        begin
>        if SameText(ACell.Data,'110') then
>           begin
>           ACell.Font.Color:=clWhite;
>           ACell.Background.Fill.Color:=clElevateRed;
>           end
>        else if SameText(ACell.Data,'144') then
>           begin
>           ACell.Font.Color:=clWhite;
>           ACell.Background.Fill.Color:=clElevateOrange;
>           end
>        else if SameText(ACell.Data,'44') then
>           begin
>           ACell.Font.Color:=clWhite;
>           ACell.Background.Fill.Color:=clElevateGreen;
>           end
>        else
>           ACell.RefreshInterface;
>        end;
> end;
>
> The RefreshInterface call is necessary to ensure that the cell is displayed in a "normal" fashion if it was previously given a different background color due to the custom cell updates that are being done.
>
> You can test the interface state of a cell to determine if it's selected, focused, etc.  The state names are in the WebCtrls unit at the top in the const section:
>
>     { State names }
>
>     NONE_STATE_NAME = 'None';  // Used for refreshing interface states (is a non-operation)
>     NORMAL_STATE_NAME = 'Normal';
>     DISABLED_STATE_NAME = 'Disabled';
>     HOT_STATE_NAME = 'Hot';
>     FOCUSED_STATE_NAME = 'Focused';
>     PUSHED_STATE_NAME = 'Pushed';
>     MINIMIZED_STATE_NAME = 'Minimized';
>     READONLY_STATE_NAME = 'ReadOnly';
>     ACTIVE_STATE_NAME = 'Active';
>     EMPTY_STATE_NAME = 'Empty';
>     SELECTED_STATE_NAME = 'Selected';
>     BOTH_STATE_NAME = 'Both';
>     HIDDEN_STATE_NAME = 'Hidden';
>     ERROR_STATE_NAME = 'Error';
>
> Not all of these apply to grid cells, of course.
>
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
Wed, Feb 3 2016 2:45 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi Tim,

How about following? Where can I (if I can) put "ACell.RefreshInterface"?

if (ACell.Index mod 2) = 0 then
 begin
   ACell.Font.Size := 12;
   ACell.Font.Color := clBlack;
   ACell.Background.Fill.Color := clWhite;
 end
 else
 begin
     ACell.Font.Size := 12;
     ACell.Font.Color := clBlack;
     ACell.Background.Fill.Color:=clAliceBlue;
 end;

Thanks Smile

Regards,
Hüseyin


On 03-02-2016 20:38, Tim Young [Elevate Software] wrote:
> Uli,
>
> << How can I do that? >>
>
> Use something like this:
>
> procedure TForm1.GridColumn5CellUpdate(Sender: TObject; ACell: TGridCell);
> begin
>     if SameText(ACell.InterfaceState,NORMAL_STATE_NAME) then  << This is the key test !
>        begin
>        if SameText(ACell.Data,'110') then
>           begin
>           ACell.Font.Color:=clWhite;
>           ACell.Background.Fill.Color:=clElevateRed;
>           end
>        else if SameText(ACell.Data,'144') then
>           begin
>           ACell.Font.Color:=clWhite;
>           ACell.Background.Fill.Color:=clElevateOrange;
>           end
>        else if SameText(ACell.Data,'44') then
>           begin
>           ACell.Font.Color:=clWhite;
>           ACell.Background.Fill.Color:=clElevateGreen;
>           end
>        else
>           ACell.RefreshInterface;
>        end;
> end;
>
> The RefreshInterface call is necessary to ensure that the cell is displayed in a "normal" fashion if it was previously given a different background color due to the custom cell updates that are being done.
>
> You can test the interface state of a cell to determine if it's selected, focused, etc.  The state names are in the WebCtrls unit at the top in the const section:
>
>     { State names }
>
>     NONE_STATE_NAME = 'None';  // Used for refreshing interface states (is a non-operation)
>     NORMAL_STATE_NAME = 'Normal';
>     DISABLED_STATE_NAME = 'Disabled';
>     HOT_STATE_NAME = 'Hot';
>     FOCUSED_STATE_NAME = 'Focused';
>     PUSHED_STATE_NAME = 'Pushed';
>     MINIMIZED_STATE_NAME = 'Minimized';
>     READONLY_STATE_NAME = 'ReadOnly';
>     ACTIVE_STATE_NAME = 'Active';
>     EMPTY_STATE_NAME = 'Empty';
>     SELECTED_STATE_NAME = 'Selected';
>     BOTH_STATE_NAME = 'Both';
>     HIDDEN_STATE_NAME = 'Hidden';
>     ERROR_STATE_NAME = 'Error';
>
> Not all of these apply to grid cells, of course.
>
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
Thu, Feb 4 2016 3:15 AMPermanent Link

Uli Becker

Tim,

thanks. It was my first idea to look for a property like "status", but didn't find it in the manual.

Uli
Thu, Feb 4 2016 12:17 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Huseyin,

<< How about following? Where can I (if I can) put "ACell.RefreshInterface"? >>

If you're always explicitly setting the cell colors, etc., then you don't need the RefreshInterface call.  The RefreshInterface call is only for situations where you want the *default* display of the cell, after having (possibly) modified it at some point in the OnCellUpdate event handler.

Tim Young
Elevate Software
www.elevatesoft.com
Image