protected virtual void OnNodeDragDroping(DragDropNodeEventArgs e) { if (NodeDragDroping != null) { NodeDragDroping(this, e); } }
protected override void OnDragDrop(DragEventArgs drgevent) { try { //拖拽结束 InvalidatePrevLine(true); ///获取拖拽结果 _dropResultNode = (TreeNodePro)this.GetNodeAt(PointToClient(Control.MousePosition)); ///鼠标当前位置没有TreeNode,那么认为在最后一个之后 if (_dropResultNode == null) { _dropResultNode = (TreeNodePro)this.Nodes[this.Nodes.Count - 1]; } ///恢复一些辅助变量为初始化状态 _isDragDrop = false; _beginPoint = Point.Empty; ///判断目标节点是否不是选择节点;或者不在选择节点的子节点内; /// ///注:(by zhucai)判断一个一个节点是否是另一节点的孙节点不能通过node.FullPath.StartWith的方式, ///因为可能出现上级节点名刚好等于当前节点祖节点的前面部分。 if (Array.IndexOf(_dropNodes, _dropResultNode) == -1 && !CheckNodeParent(_dropResultNode, _dropNodes)) { //触发NodeDragDroping事件 DragDropNodeEventArgs ddn = new DragDropNodeEventArgs(drgevent, new DragDropResult(_dropNodes, _dropResultNode, GetDragDropResult())); OnNodeDragDroping(ddn); if (!ddn.Cancel) { /* ///先从树里删除 _dropNode.Remove(); ///计算该插入的位置 int insertIndex = 0; TreeNode parentNode = null; switch (ddn.DragDropResult.DropType) { case DragDropResultType.Before: parentNode = ddn.DragDropResult.DropPutNode.Parent; insertIndex = ddn.DragDropResult.DropPutNode.Index; break; case DragDropResultType.After: parentNode = ddn.DragDropResult.DropPutNode.Parent; insertIndex = ddn.DragDropResult.DropPutNode.Index + 1; break; case DragDropResultType.Into: parentNode = ddn.DragDropResult.DropPutNode; insertIndex = parentNode.Nodes.Count; break; default: Debug.Assert(false); break; } ///插入树中 if (parentNode != null) { parentNode.Nodes.Insert(insertIndex, (BaseTreeNode)_dropNode); } else { this.Nodes.Insert(insertIndex, (BaseTreeNode)_dropNode); } */ ///触发NodeDragDroped事件 OnNodeDragDroped(ddn); } } //this.SelectedNodes.AddRange(_dropNodes); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } base.OnDragDrop(drgevent); }