Hello!
Just started with TeeTree and need some guidance how to approach the following problems:
I want to use drag and drop between nodes, but I have to be able to control wich nodes are allowed to be dropped on wich nodes! When I enable the DragAndDrop.Automatic it permitts drop on any node without fiering the OnDragOver event. Do I have to manage it all manually, and if, do you have any sample code?
In the TTree.OnClickShape event i want to add children to the clicked node and make the first one of the added children the "selected" node. I tried with TreeNodeShape.Selected := True; (TreeNodeShape beeing the added child) but it's still the clicked node that becomes the selected one.
Regards, Mikael
How to code...
Re: How to code...
Hi Michael,
I think you should control manually the drag and drop process. Something like following:Lenfors wrote:I want to use drag and drop between nodes, but I have to be able to control wich nodes are allowed to be dropped on wich nodes! When I enable the DragAndDrop.Automatic it permitts drop on any node without fiering the OnDragOver event. Do I have to manage it all manually, and if, do you have any sample code?
Code: Select all
var dragginShape: TTreeNodeShape;
procedure TForm1.FormCreate(Sender: TObject);
begin
Tree1.DragAndDrop.Automatic:=false;
end;
procedure TForm1.Tree1AfterDraw(Sender: TObject);
begin
if dragginShape <> nil then
Caption:='dragging';
end;
procedure TForm1.Tree1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
dragginShape:=Tree1.ClickedShape(X,Y);
end;
procedure TForm1.Tree1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var parentShape: TTreeNodeShape;
connection: TTreeConnection;
// Returns True when AShape can be a child node of AParent
Function CanBeParentOf(AParent,AShape:TTreeNodeShape):Boolean;
begin
result:=False;
if Assigned(AParent) and Assigned(AShape) and
(AParent<>AShape) and (AParent<>AShape.Parent) then
begin
While Assigned(AParent.Parent) do
if AParent.Parent=AShape then Exit
else AParent:=AParent.Parent;
result:=True;
end;
end;
begin
if dragginShape <> nil then
begin
parentShape:=Tree1.ClickedShape(X,Y);
if parentShape <> nil then
begin
if CanBeParentOf(parentShape,dragginShape) then
begin
parentShape.AddConnection(dragginShape);
dragginShape.Parent:=parentShape;
end;
end;
end;
end;
You can try using similar code as following to force a node selection at OnMouseDown event:Lenfors wrote:In the TTree.OnClickShape event i want to add children to the clicked node and make the first one of the added children the "selected" node. I tried with TreeNodeShape.Selected := True; (TreeNodeShape beeing the added child) but it's still the clicked node that becomes the selected one.
Code: Select all
TreeNodeShape1.Selected:=true;
Tree1.CancelMouse:=true;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |