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