TAdvCheckTreeView: Reordering & Selected Node...

I'm using the "Reorder" feature of the TAdvCheckTreeView. Everything seem to work fine. However, I'd like to keep the reordered node as the selected node i.e. the one that is "dragged". This isn't the normal behavior of the reordering mechanism - normally there isn't a node selected after the reordering process.


I've tried this code:

procedure TDistrictTableColumnsForm.ctvColumnsAfterReorderNode(Sender: TObject; AFromNode, AToNode: TAdvTreeViewVirtualNode);
begin
	ctvColumns.SelectedNode := ctvColumns.Nodes[AToNode.Index];
end;

But it doesn't selected the right node.

Thanks - Steve

Hi,


We have investigated this here and you can use the following code to accomplish this.



type
  TForm1 = class(TForm)
    AdvCheckedTreeView1: TAdvCheckedTreeView;
    procedure AdvCheckedTreeView1BeforeReorderNode(Sender: TObject; AFromNode,
      AToNode: TAdvTreeViewVirtualNode; var ACanReorder: Boolean);
    procedure AdvCheckedTreeView1AfterReorderNode(Sender: TObject; AFromNode,
      AToNode: TAdvTreeViewVirtualNode);
  private
    { Private declarations }
    FNodeIndex: Integer;
  public
    { Public declarations }
  end;


...
implementation
...



procedure TForm1.AdvCheckedTreeView1AfterReorderNode(Sender: TObject;
  AFromNode, AToNode: TAdvTreeViewVirtualNode);
var
  p: TAdvTreeViewNode;
begin
  if Assigned(AToNode.Node) then
  begin
    p := AToNode.Node.GetParent;
    if Assigned(p) and (FNodeIndex >= 0) and (FNodeIndex <= p.Nodes.Count - 1) then
      AdvCheckedTreeView1.SelectNode(p.Nodes[FNodeIndex]);
  end;
end;


procedure TForm1.AdvCheckedTreeView1BeforeReorderNode(Sender: TObject;
  AFromNode, AToNode: TAdvTreeViewVirtualNode; var ACanReorder: Boolean);
begin
  FNodeIndex := AToNode.Index;
end;

Pieter Scheldeman2019-02-12 09:29:19

Thanks Pieter!


I had to adjust the code a little since all my nodes have a nil parent i.e. they're root nodes

Here's how it looks:


Best regards,

Steve 

Very nice indeed ! If you wish to have your application (which is using our components) listed on our website feel free to contact us by email at info@tmssoftware.com ;-)
Pieter Scheldeman2019-02-12 14:33:13