TREEVIEW节点拖拽



|
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节点拖拽的更多相关文章
- TreeView 节点拖拽
public Form1() { InitializeComponent(); treeView1.AllowDrop = true; treeView1.ItemDrag += new ItemDr ...
- jstree 节点拖拽保存数据库
需要jstree具有拖拽功能需要在加载jstree时添加dnd插件,具体看代码: $('**').jstree({ //plugins-各种jstree的插件引入,展示树的多样性 'plugins' ...
- winform 两个TreeView间拖拽节点
/// <summary> /// 正在拖拽的节点 /// </summary> private TreeNode DragNode = null; /// <summa ...
- easyui树节点拖拽排序的存储过程
easyui树的拖拽排序功能 easyui树中有拖拽功能 树结构如下: 一个行政区域对应一个单位,一个单位对应多个部门,每个部门下有相关人员,功能要求: (1)行政区域没有子节点,点击text加载部门 ...
- C# TreeView 拖拽节点到另一个容器Panel中简单实现
C# TreeView 拖拽节点到另一个容器Panel中简单实现 用了这么久C#拖拽功能一直没有用到也就没用过,今天因为项目需要,领导特地给我简单讲解了下拖拽功能,真是的大师讲解一点通啊.特地写一篇博 ...
- TREEVIEW拖拽对应修改目录
附件:http://files.cnblogs.com/xe2011/TreeView_Drag_Directory%E6%93%8D%E4%BD%9C.rar TREEVIEW拖拽对应修改目 ...
- Jquery实现可拖拽的树菜单
效果图例如以下所看到的:下载地址http://download.csdn.net/detail/javaquentin/8290417 <html xmlns="http://www. ...
- html5 Sortable.js 拖拽排序源码分析
最近公司项目经常用到一个拖拽 Sortable.js插件,所以有空的时候看了 Sortable.js 源码,总共1300多行这样,写的挺完美的. 本帖属于原创,转载请出名出处. 官网http:// ...
- twaver拓扑图拖拽后保存json数据
功能描述:拓扑图.对节点进行拖拽,序列化获取拓扑图信息,保存到本地localStorage,刷新页面,执行反序列化,从本地获取之前保存的数据,展现之前拖拽后的拓扑 拓展:此处存储用的是web本地存储l ...
随机推荐
- javascript图片预先加载
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- C# mvc 验证码3
//// <summary> /// 生成验证码 /// </summary> /// <param name="length">指定验证码的长 ...
- javascript日用代码集合(一)
获取url参数 function get_url_param(name){ var reg = new RegExp("(^|&)" + name + "=([^ ...
- Git如何Check Out出指定文件或者文件夹
原文 http://www.handaoliang.com/a/20140506/195406.html 在进行项目开发的时候,有时候会有这样的需求那就是:我们只希望从Git仓库里取指定的文件或者文 ...
- Silicon Labs电容式触摸感应按键技术原理及应用
市场上的消费电子产品已经开始逐步采用触摸感应按键,以取代传统的机械式按键.针对此趋势,Silicon Labs公司推出了内置微控制器(MCU)功能的电容式触摸感应按键(Capacitive Touch ...
- PHP日常杂记
1.php点击按钮跳转页面 <input type="button" onclick="window.location.href='login.php'" ...
- java数组遍历——iterator和for方法
import Java.util.ArrayList; import java.util.Iterator; import java.util.List; public class ArrayTest ...
- restful风格,restcontroller与controller
restful风格,restcontroller与controller 初步接触springmvc的时候,被要求使用restful风格,彼时一头雾水,不懂何谓restful,参阅了很多资料,慢慢的接触 ...
- 14.5.5.1 An InnoDB Deadlock Example 一个InnoDB 死锁实例
14.5.5.1 An InnoDB Deadlock Example 一个InnoDB 死锁实例 下面的例子演示了一个错误可以发生当一个lock 请求会导致一个死锁,例子设计2个客户端,A和B: J ...
- xlslib安装, aclocal-1.13: command not found, 安装升级autoconf-2.65.tar.gz, automake-1.13.tar.gz两个文件
问题1: $ make CDPATH="${ZSH_VERSION+.}:" && cd . && aclocal-1.13 -I m4 /bin/ ...