Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread OnCellupdate issue
Mon, Feb 19 2018 8:19 AMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi All,

I want to change background color and font color for selected row in a
grid. I am using following code:

    // Check for not active/selected rows:

     if (ACell.index mod 2=0) and
(SameText(ACell.InterfaceState,NORMAL_STATE_NAME)) and (ACell.Index <>
ServiceGrid.RowIndex) then begin
     ACell.Font.Size := 12;
     ACell.Font.Color := clBlack;
     ACell.Background.Fill.Color := clWhite;
     end
     else if (ACell.Index <> ServiceGrid.RowIndex) and
(SameText(ACell.InterfaceState,NORMAL_STATE_NAME)) then
     begin
     ACell.Font.Size := 12;
     ACell.Font.Color := clBlack;
     ACell.Background.Fill.Color:=clWhiteSmoke;
     end;

    // Check for active/selected row and change color:

     if (ACell.Index = ServiceGrid.RowIndex) and
(SameText(ACell.InterfaceState,BOTH_STATE_NAME)) then begin
     ACell.Font.Size := 12;
     ACell.Font.Color := clWhite;
     ACell.Background.Fill.Color := clRed;
     end;

It kinda works, it shows correctly for the beginning of the grid, but in
the middle or bottom of the grid (scrolling) the font color are ignored
- shows in color black, background color red is still ok. Can anyone
spot what's going on?

Regards,

Hüseyin

Thu, Feb 22 2018 3:54 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Huseyin,

<< It kinda works, it shows correctly for the beginning of the grid, but in the middle or bottom of the grid (scrolling) the font color are ignored - shows in color black, background color red is still ok. Can anyone spot what's going on? >>

There are two issues that I can see:

1) If you want to alternate colors via the mod function, you don't want to mod the cell index, you want to mod the row index.

2) When comparing the cell index against the row index, you need to make sure to subtract the RowOffset property from the RowIndex property.  Otherwise, you're comparing apples to oranges. Smile

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Feb 22 2018 6:15 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

Huseyin

<<<
if (ACell.Index = ServiceGrid.RowIndex) and
          (SameText(ACell.InterfaceState,BOTH_STATE_NAME)) then begin
  ACell.Font.Size := 12;
  ACell.Font.Color := clWhite;
  ACell.Background.Fill.Color := clRed;
end;

>>>

ACell.Index refers to the index of the cell in the grid column.
ServiceGrid.RowIndex is index of the current row in the grid control

So they are not comparable.

It will "work" whilst the number of columns in the grid control is less than the index of the current row in the grid.

Richard
Image