2

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?

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
Tallys Ferrante
  • 173
  • 1
  • 13

1 Answers1

1

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:

  • In Delphi 10.1 Berlin the above fix is not needed.

  • In Delphi 10 Seattle and earlier (I verified down to XE6) the fix is needed

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).

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • Thanks @Tom Brunberg, worked perfectly, i only added a `if (Sender as TGrid).ColumnByIndex(ACol+1) <> nil then` before select the next column – Tallys Ferrante Nov 08 '16 at 12:19
  • @Tallys Ferrante You are welcome! I don't see why your addition would be necessary. So which version are you working with? – Tom Brunberg Nov 08 '16 at 12:48
  • I m using Delphi Seattle. I add this verification because my last column is invisible too, so if the user press the arrow unintentionally the app do not raise an access violation when trying to select the next column(that does not exist). – Tallys Ferrante Nov 08 '16 at 14:47
  • @Tally Ahh, yes in that case. I hope you don't mind if I add it to my answer, for completeness sake. – Tom Brunberg Nov 08 '16 at 15:12