Exemplo n.º 1
0
        void MultiSourceTreeView_DragOverNode(object sender, DragOverNodeEventArgs e)
        {
            // Verify that the nodes are the correct type for this operation.
            if (!(e.Node is MultiSourceTreeNode) || !(e.TargetNode is MultiSourceTreeNode))
            {
                return;
            }

            MultiSourceTreeNode node       = (MultiSourceTreeNode)e.Node;
            MultiSourceTreeNode targetNode = (MultiSourceTreeNode)e.TargetNode;

            // For now, we are only allowing dropping of nodes that have a single info entry.
            if (node.EntryCount != 1)
            {
                e.Cancel = true;
            }
            else if (targetNode.EntryCount != 1)
            {
                e.Cancel = true;
            }
            else
            {
                e.Cancel = !(node.InfoEntries[0].NodeType.ParentSource.CanDropInto(
                                 targetNode.InfoEntries[0].NodeType, node.InfoEntries[0].NodeType));
            }
        }
Exemplo n.º 2
0
        private void BetterTreeView_DragOver(object sender, DragEventArgs e)
        {
            DragScroll();

            // Compute drag position and move image
            Point formP = PointToClient(new Point(e.X, e.Y));

            DragHelper.ImageList_DragMove(formP.X - Left, formP.Y - Top);

            // Get actual drop node
            TreeNode dropNode = GetNodeAt(PointToClient(new Point(e.X, e.Y)));

            // Make sure we have a node.
            if (dropNode == null)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            if (tempDropNode != dropNode)
            {
                DragHelper.ImageList_DragShowNolock(false);
                SelectedNode = dropNode;
                DragHelper.ImageList_DragShowNolock(true);
                tempDropNode = dropNode;
            }

            // Make sure that we aren't dropping onto a child node.
            TreeNode tmpNode = dropNode;

            while (tmpNode.Parent != null)
            {
                if (tmpNode.Parent == dragNode)
                {
                    e.Effect = DragDropEffects.None;
                    return;
                }
                tmpNode = tmpNode.Parent;
            }

            // Allow any event handlers a chance to cancel the drag/drop.
            DragOverNodeEventArgs args = new DragOverNodeEventArgs(dragNode, dropNode);

            if (DragOverNode != null)
            {
                DragOverNode(this, args);
            }
            if (args.Cancel)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            e.Effect = DragDropEffects.All;
        }