delphifiremonkeydelphi-10-seattletgrid

Delphi Firemonkey Grid: Invisible Columns When Navigating


i have a TGrid on FMX with 3 columns, the second column is Visible False, if I click the first column and press the arrow to focus on the next visible column, the cursor does not go to the third column, it disappears, as if focusing on the second column, and if I push arrow again, then he goes to the third column.

How can i fix it?


Solution

  • Use the OnSelectCell event as follows:

    procedure TForm7.Grid1SelectCell(Sender: TObject; const ACol, ARow: Integer;
      var CanSelect: Boolean);
    begin
      if not (Sender as TGrid).Columns[ACol].Visible then
      begin
        CanSelect := False;
        if (Sender as TGrid).ColumnByIndex(ACol+1) <> nil then
          (Sender as TGrid).SelectColumn(ACol+1);
      end;
    end;
    

    Btw, you did not say which version of Delphi you are using, and there are differences. Please, when asking about Firemonkey, always tag the question with your version of Delphi. Here's an update:

    You may also have noticed that selecting in the other direction (right to left) works without the fix in versions Delphi 10 Seattle and earlier (which explains why only ACol + 1 needs to be considered).