private int draptype=;//1:不同级,   不为1:拖同级
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
} private void treeView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(TreeNode)))
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
} private void treeView1_DragDrop(object sender, DragEventArgs e)
{
//获得拖放中的节点
TreeNode moveNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
//根据鼠标坐标确定要移动到的目标节点
Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
TreeNode targetNode = treeView1.GetNodeAt(pt);
//如果目标节点为分组则添加到下级节点的未端,如果目标节点为素材文件则添加为同级节点
TreeNode NewMoveNode = (TreeNode)moveNode.Clone();
if (draptype == )
{
targetNode.Nodes.Insert(targetNode.Nodes.Count, NewMoveNode); }
else
{
if (moveNode.NextNode == targetNode)
{
targetNode.Parent.Nodes.Insert(targetNode.Index + , NewMoveNode);
}
else
{
targetNode.Parent.Nodes.Insert(targetNode.Index, NewMoveNode);
}
}
//更新当前拖动的节点选择
treeView1.SelectedNode = NewMoveNode;
//展开目标节点,便于显示拖放效果
targetNode.Expand(); //移除拖放的节点
moveNode.Remove(); }

WinForm中TreeView控件实现鼠标拖动节点(可实现同级节点位置互换,或拖到目标子节点)的更多相关文章

  1. Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼

    Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼标签: winform treeview drawnode Treeview控 ...

  2. C#Winform中treeView控件使用总结

    1.如何展开结点时改变图标(注意:不是选中时) 要在目录中使用图标首先要加入一个控件ImageList(命名为imageList1),然后可以按图片的index或名称引用图片. 然后需要在TreeVi ...

  3. WinForm 中TreeView 控件的使用实例

    新建一个窗体,在本窗体界面上需要以下几个按钮 (一个TreeView    一个 TextBox  三个Button 按钮) 后台代码如下: using System; using System.Co ...

  4. C#之Winform中treeview控件绑定数据库

    private DataSet ds; private SqlDataAdapter sqlDataAdapter1; private int maxnodeid; private void Form ...

  5. Winform中checklistbox控件的常用方法

    Winform中checklistbox控件的常用方法最近用到checklistbox控件,在使用其过程中,收集了其相关的代码段1.添加项checkedListBox1.Items.Add(" ...

  6. [C#]WinForm 中 comboBox控件之数据绑定

    [C#]WinForm 中 comboBox控件之数据绑定 一.IList 现在我们直接创建一个List集合,然后绑定 IList<string> list = new List<s ...

  7. C#设置一个控件可以鼠标拖动

    C#设置一个控件可以鼠标拖动: 新建一个C#项目, 创建一个label控件, 设置label的鼠标按下和抬起事件分别为:label1_MouseDown和label1_MouseUp. 对代码进行如下 ...

  8. C# WinForm中 让控件全屏显示的实现代码

    夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...

  9. Win32中TreeView控件的使用方法,类似于资源管理器中文件树形显示方式

    首先是头文件,内容如下: #include <tchar.h> #include "..\CommonFiles\CmnHdr.h" #include <Wind ...

随机推荐

  1. Oracle笔记3-高级查询

    高级查询 1.关联查询 作用:可以跨多表查询 --查询出员工的名字和他所在部门的名字 //错误//select first_name,name from s_emp,s_dept; //错误原因:产生 ...

  2. 为windows应用程序提供托盘图标

    1>包含头文件 #include "Shellapi.h"   2>相关结构体和函数:     NOTIFYICONDATA     WINSHELLAPI BOOL ...

  3. 2016 、12 、11<本周>

    翻了翻记录 想把上周没搞出来的1159和day2T2搞出来.

  4. linux软raid练习

    创建一个空间大小为10G的raid5,要求其chunk为1024k,格式为ext4文件系统,开机可自动挂载至/backup目录,并支持acl功能: 1 2 3 4 5 6 7 8 9 10 11 12 ...

  5. LeetCode 【31. Next Permutation】

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. 收集一些有用的docker镜像

    https://hub.docker.com/explore/  是star排名靠前的image =================================================== ...

  7. 关于eclipse保存代码很慢,提示the user operation is waiting的问题

    关于eclipse保存代码很慢,提示the user operation is waiting的问题 首先 去掉 project - build Automaticlly 然后 project-> ...

  8. python之正则表达式

    1) 用管道符号(|)匹配多个正则表达式 举例 at | home     匹配 at, home 2) 匹配任意一个单个的字符(.) 举例 f.o  匹配在"f"和"o ...

  9. Gridview 分多页时导出excel的解决方案

    在开发会遇到将gridview中的数据导入到excel 这样的需求,当girdview有多页数据时按照一般的方式导出的数据只可能是当前页的数据,后几页的数据还在数据库内,没有呈现到页面上,传统的方式是 ...

  10. mybatis实战教程(mybatis in action)之三:实现数据的增删改查

    前面已经讲到用接口的方式编程.这种方式,要注意的一个地方就是.在User.xml  的配置文件中,mapper namespace="com.yihaomen.mybatis.inter.I ...