假设把A节点往B节点上拖拽
那么 
A 为Node1,B为Node2
 
 
       private void Form1_Load(object sender, EventArgs e)
        {
            treeView1.AllowDrop = true;
    treeView1.HideSelection = false;

}

 
 
 
        private TreeNode node1 = null; //node1  当前选中的那个节点
        private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {  
            node1 = (TreeNode)e.Item;
             DoDragDrop(e.Item, DragDropEffects.Move);  

}

 
         private void treeView1_DragOver(object sender, DragEventArgs e)
        {
            TreeNode node2 = treeView1.GetNodeAt(treeView1.PointToClient(new Point(e.X, e.Y)));
            //节点2不存在
            //节点1 = 节点2
            //节点1 往它的父一级节点拖拽
            if ((node2 == null) || (node1 == node2) || (node1.Parent == node2))
            {
                treeView1.SelectedNode = node1;
                SetTreeNodeColorDefault();
                e.Effect = DragDropEffects.None;
                return;
            }
            else
            {
                e.Effect = DragDropEffects.Move;
                treeView1.SelectedNode = node2;
                SetTreeNodeColorBlue();
 
                //当一个父节点往它的子节点中拖拽时
                while (node2.Parent != null)
                {
                    if (node2.Parent == node1)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                    node2 = node2.Parent;
                }
            }
        }
 
         private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode node2 = treeView1.GetNodeAt( treeView1.PointToClient(new Point(e.X, e.Y)) );
            if (node1 != node2)
            {
                if (node1.Parent != node2)
                {
                    textBox1.Text = textBox3.Text + "\\" + node1.FullPath;
                    textBox2.Text = textBox3.Text + "\\" + node2.FullPath;           
                    ///MessageBox.Show("Finished");
                    if (node1.Parent == null)
                        treeView1.Nodes.Remove(node1);
                    else
                        node1.Parent.Nodes.Remove(node1);
 
                    node2.Nodes.Add(node1);
                    node2.Expand();
                }
            }

}

 
//设置颜色部分
       private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            SetTreeNodeColorDefault();

}

 
         private void SetTreeNodeColorBlue()
        {
            if (node1 != null)
            {
                node1.BackColor = Color.FromArgb(51, 153, 255);//蓝色 
                node1.ForeColor = Color.White;
            }
        }
 
 
       private void SetTreeNodeColorDefault()
        {
            if (node1 != null)
            {
                node1.BackColor = SystemColors.Window;
                node1.ForeColor = Color.Black;
            }
        }
 
 
 
 

附件列表

TREEVIEW节点拖拽的更多相关文章

  1. TreeView 节点拖拽

    public Form1() { InitializeComponent(); treeView1.AllowDrop = true; treeView1.ItemDrag += new ItemDr ...

  2. jstree 节点拖拽保存数据库

    需要jstree具有拖拽功能需要在加载jstree时添加dnd插件,具体看代码: $('**').jstree({ //plugins-各种jstree的插件引入,展示树的多样性 'plugins' ...

  3. winform 两个TreeView间拖拽节点

    /// <summary> /// 正在拖拽的节点 /// </summary> private TreeNode DragNode = null; /// <summa ...

  4. easyui树节点拖拽排序的存储过程

    easyui树的拖拽排序功能 easyui树中有拖拽功能 树结构如下: 一个行政区域对应一个单位,一个单位对应多个部门,每个部门下有相关人员,功能要求: (1)行政区域没有子节点,点击text加载部门 ...

  5. C# TreeView 拖拽节点到另一个容器Panel中简单实现

    C# TreeView 拖拽节点到另一个容器Panel中简单实现 用了这么久C#拖拽功能一直没有用到也就没用过,今天因为项目需要,领导特地给我简单讲解了下拖拽功能,真是的大师讲解一点通啊.特地写一篇博 ...

  6. TREEVIEW拖拽对应修改目录

    附件:http://files.cnblogs.com/xe2011/TreeView_Drag_Directory%E6%93%8D%E4%BD%9C.rar     TREEVIEW拖拽对应修改目 ...

  7. Jquery实现可拖拽的树菜单

    效果图例如以下所看到的:下载地址http://download.csdn.net/detail/javaquentin/8290417 <html xmlns="http://www. ...

  8. html5 Sortable.js 拖拽排序源码分析

    最近公司项目经常用到一个拖拽 Sortable.js插件,所以有空的时候看了 Sortable.js 源码,总共1300多行这样,写的挺完美的.   本帖属于原创,转载请出名出处. 官网http:// ...

  9. twaver拓扑图拖拽后保存json数据

    功能描述:拓扑图.对节点进行拖拽,序列化获取拓扑图信息,保存到本地localStorage,刷新页面,执行反序列化,从本地获取之前保存的数据,展现之前拖拽后的拓扑 拓展:此处存储用的是web本地存储l ...

随机推荐

  1. fedora22 无法联网的情况下rpm安装gcc5.1

    前天发生件很不幸的事.我在给ubuntu14.04安装NVIDIA显卡驱动的时候,想清空下一个目录,什么目录我也忘了,当时我正好切到root身份(平常我很少切root的),命令格式如下 rm -fr ...

  2. excel快递单号查询工具以及源码

    Function kdcx(kd, orderid) Dim Err, url, kdtime, link, Errcode, Status Select Case kd '此处支持的快递公司很多的 ...

  3. Android Capability 细粒度的权限控制

    1. 传统的UID/GID,权限颗粒度太大 2. Capability: 细粒度的权限控制 3. 进程的Capability 4. 文件的Capability 5. 进程的Capability Bou ...

  4. Python Standard Library 学习(一) -- Built-in Functions 内建函数

    内建函数列表 Built-in Functions abs() divmod() input() open() staticmethod() all() enumerate() int() ord() ...

  5. Dictionary通过Value找到它的key

    private void GetDicKeyByValue() { Dictionary<string, string> dic = new Dictionary<string, s ...

  6. 从文章"避免复制与粘贴"到文章"Extract Method"的反思(1)

    看了一个比我牛的人的博客园的博文"避免复制和粘贴".里面提到了重构手法Extract Method.  所以又搜了一下Extract Method. 这里先自我理解Extract ...

  7. JSP 结构

    网络服务器需要一个JSP引擎,也就是一个容器来处理JSP页面. 容器负责截获对JSP页面的请求.本教程使用内嵌JSP容器的Apache来支持JSP开发. JSP容器与Web服务器协同合作,为JSP的正 ...

  8. show

    showproperties thefrm.Controls --显示属性??showmethods thefrm.Menu---显示功能?? showclass "*bitmap*&quo ...

  9. DBA - 我的学习

    DBA - 我的学习 1. df -k 检查oracle 分区硬盘使用情况 2. 检查alert_<SID名称>.log, alert日志文件,检查是否新增错误日志 3. 检查数据文件的状 ...

  10. 深入了解一下PYTHON中关于SOCKETSERVER的模块-A

    有了这块知识,应该对各类WEB框架有更好的理解吧..FLASK,DJANGO,WEBPY.... #!/usr/bin/env python from BaseHTTPServer import HT ...