TMSFNCTreeView.OnBeforeReorderNode

Perhaps I'm misunderstanding the OnBeforeReorderNode but this event doesn't seem to be working. My understanding is that it should be called when a tree node is moved so that the move can be accepted or rejected. I want to reject the move unless the SHIFT key is currently pressed, I'd really like to disable it in an event before the drag operation begins but there's no OnBeforeDrag event and so that makes the OnBeforeReorderNode even more important.

Hi,

The OnBeforeReorderNode is called before the moment a node is to be reordered. This works together with Interaction.Reorder := True. Drag & Drop is handled differently, with Interaction.DragDropMode. You cannot change the behavior of the Reorder feature, but you can change the way the drag-drop feature is working with the following code.

unit Unit48;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.TMSFNCTypes, FMX.TMSFNCUtils, FMX.TMSFNCGraphics, FMX.TMSFNCGraphicsTypes,
  FMX.TMSFNCCustomControl, FMX.TMSFNCTreeViewBase, FMX.TMSFNCTreeViewData,
  FMX.TMSFNCCustomTreeView, FMX.TMSFNCTreeView;

type
  TTMSFNCTreeViewEx = class(TTMSFNCTreeView)
  private
    FShift: TShiftState;
  protected
    procedure HandleMouseDown(Button: TTMSFNCMouseButton; Shift: TShiftState; X, Y: Single); override;
    function CanStartDragFromMouseDown: Boolean; override;
  end;

  TForm48 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form48: TForm48;

implementation

{$R *.fmx}

procedure TForm48.FormCreate(Sender: TObject);
var
  t: TTMSFNCTreeViewEx;
begin
  t := TTMSFNCTreeViewEx.Create(Self);
  t.Parent := Self;
  t.InitSample;
  t.Interaction.DragDropMode := tdmMove;
end;

{ TTMSFNCTreeViewEx }

function TTMSFNCTreeViewEx.CanStartDragFromMouseDown: Boolean;
begin
  Result := ssShift in FShift;
end;

procedure TTMSFNCTreeViewEx.HandleMouseDown(Button: TTMSFNCMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  FShift := Shift;
  inherited;
end;

end.

Thank you, that worked well.

1 Like