Exemplo n.º 1
0
        private void EntityView_DragDrop(object sender, DragEventArgs e)
        {
            EntityTreeNode NewNode;

            if (e.Data.GetDataPresent(typeof(EntityTreeNode).FullName, false))
            {
                System.Drawing.Point pt = ((TreeView)sender).PointToClient(new System.Drawing.Point(e.X, e.Y));
                EntityTreeNode       DestinationNode = (EntityTreeNode)((TreeView)sender).GetNodeAt(pt);
                NewNode = (EntityTreeNode)e.Data.GetData(typeof(EntityTreeNode).FullName);


                if (DestinationNode == null)
                {
                    if (NewNode.Entity.Parent != null)
                    {
                        NewNode.Entity.Parent.RemoveEntity(NewNode.Entity, true);
                        NewNode.Remove();
                        EntityView.Nodes.Add(NewNode);
                    }
                }
                else
                if (DestinationNode.TreeView == EntityView)
                {
                    Entity ent = DestinationNode.Entity;
                    do
                    {
                        if (NewNode.Entity == ent)
                        {
                            return;
                        }
                        ent = ent.Parent;
                    } while (ent != null);

                    EntityView.BeginUpdate();
                    NewNode.Remove();
                    DestinationNode.Entity.AddEntity(NewNode.Entity);
                    DestinationNode.Nodes.Add(NewNode);
                    DestinationNode.Expand();
                    EntityView.EndUpdate();
                }
            }
        }