TTMSFMXGrid Centered Checkbox Issue

We have a decendant Grid component, and in this grid we want checkbox always to be centered within the grid-cell.
So that's why have overriden the DoGetCellAppearance method (see code below).

However this gives problems while clicking/checking the checkboxes in the grid.
The row-number seems to be calculated wrongly and we end up checking a different checkbox than intended.
You can also visually see this while hovering over the checkboxes and see the color of the checkbox change from black to blue and back.

Should I use a different method to override or is there another way to center te checkboxes?
If you have any questions just let me know.

TIA
John


type
  TMyGrid = class(TTMSFMXGrid)
  protected
    function GetClassStyleName: string; override;
    procedure DoGetCellAppearance(ACol, ARow: Integer; Cell: TFMXObject; ACellState: TCellState); override;
  end;
  
{ TMyGrid }

procedure TMyGrid.DoGetCellAppearance(ACol, ARow: Integer; Cell: TFMXObject; ACellState: TCellState);
begin
  inherited;

  if (Cell is TTMSFMXCheckGridCell) then
    (Cell as TTMSFMXCheckGridCell).Checkbox.Align := TAlignLayout.Center;
end;


function TMyGrid.GetClassStyleName: string;
begin
  Result := ClassParent.ClassName + 'style';
  Delete(Result, 1, 1);
end;


procedure TForm1.FormCreate(Sender: TObject);
var 
  FGrid : TMyGrid;
begin
  FGrid         := TMyGrid.Create(Self);
  FGrid.Parent  := Self;
  FGrid.Align   := TAlignLayout.Bottom;
  FGrid.Height  := 200;
  FGrid.Visible := True;

  InitGrid(FGrid, 'My');
end;


procedure TForm1.InitGrid(AGrid: TTMSFMXGrid; APrefix: string);
var
  c, r: Integer;
begin
  AGrid.ColumnCount := 100;
  AGrid.RowCount    := 50;

  AGrid.Options.Filtering.DropDown    := True;
  AGrid.Options.Filtering.MultiColumn := True;
  AGrid.Options.Mouse.ColumnDragging  := True;
  AGrid.Options.Mouse.ColumnSizing    := True;

  AGrid.Columns[0].ColumnType := ctCheckBox;
  AGrid.ColumnWidths[0]       := 40;
  AGrid.FixedColumns          := 0;

  for c := 1 to AGrid.ColumnCount - 1 do
  begin
    AGrid.ColumnWidths[c] := 80;

    for r := 0 to AGrid.RowCount - 1 do
    begin
      if (r >= AGrid.FixedRows) and (c mod 3 = 2) then
        AGrid.Cells[c, r] := dummyTexts[r mod 10]
      else
        AGrid.Cells[c, r] := Format('%s-%d:%d', [APrefix, c, r]);
    end;
  end;
end;

Hi,


You can use the following code the achieve this


procedure TMyGrid.DoGetCellProperties(ACol, ARow: Integer; Cell: TFMXObject);
var
  r: TRectF;
begin
  inherited;
   if (Cell is TTMSFMXCheckGridCell) then
   begin
     (Cell as TTMSFMXCheckGridCell).Checkbox.Width := 16;
     (Cell as TTMSFMXCheckGridCell).Checkbox.Height := 16;
     (Cell as TTMSFMXCheckGridCell).Checkbox.Align := TAlignLayout.None;
     r := (Cell as TTMSFMXCheckGridCell).LocalRect;
     (Cell as TTMSFMXCheckGridCell).Checkbox.SetBounds(r.Left + (r.Width - 16) / 2, r.Top + (r.Height - 16) / 2, 16, 16);
   end;
end;

Hi Pieter,
Thx, I am gonna try this asap.