Treeview如何实现拖拽功能

wfox111 2004-11-04 03:40:00
我想在两棵树之间进行拖拽,请问该如何实现
跟者有分
...全文
214 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wfox111 2004-11-16
  • 打赏
  • 举报
回复
多谢各位
xq02 2004-11-04
  • 打赏
  • 举报
回复
收到没有?
wfox111 2004-11-04
  • 打赏
  • 举报
回复
wfox111@163.com
wfox111@sina.com
再次感谢
xq02 2004-11-04
  • 打赏
  • 举报
回复
给个信箱,我给你发个例子
wfox111 2004-11-04
  • 打赏
  • 举报
回复
不知道在页面中时候合适
wq_sc 2004-11-04
  • 打赏
  • 举报
回复
学习!
wfox111 2004-11-04
  • 打赏
  • 举报
回复
先谢了,好好看看
server_me 2004-11-04
  • 打赏
  • 举报
回复
跟,~~
trnbo 2004-11-04
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
private TreeView treeView1;

public Form1()
{
treeView1 = new TreeView();

this.SuspendLayout();

// Initialize treeView1.
treeView1.AllowDrop = true;
treeView1.Dock = DockStyle.Fill;

// Add nodes to treeView1.
TreeNode node;
for (int x = 0; x < 3; ++x)
{
// Add a root node to treeView1.
node = treeView1.Nodes.Add(String.Format("Node{0}", x*4));
for (int y = 1; y < 4; ++y)
{
// Add a child node to the previously added node.
node = node.Nodes.Add(String.Format("Node{0}", x*4 + y));
}
}

// Add event handlers for the required drag events.
treeView1.ItemDrag += new ItemDragEventHandler(treeView1_ItemDrag);
treeView1.DragEnter += new DragEventHandler(treeView1_DragEnter);
treeView1.DragOver += new DragEventHandler(treeView1_DragOver);
treeView1.DragDrop += new DragEventHandler(treeView1_DragDrop);

// Initialize the form.
this.ClientSize = new Size(292, 273);
this.Controls.Add(treeView1);

this.ResumeLayout(false);
}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
// Move the dragged node when the left mouse button is used.
if (e.Button == MouseButtons.Left)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}

// Copy the dragged node when the right mouse button is used.
else if (e.Button == MouseButtons.Right)
{
DoDragDrop(e.Item, DragDropEffects.Copy);
}
}

// Set the target drop effect to the effect
// specified in the ItemDrag event handler.
private void treeView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.AllowedEffect;
}

// Select the node under the mouse pointer to indicate the
// expected drop location.
private void treeView1_DragOver(object sender, DragEventArgs e)
{
// Retrieve the client coordinates of the mouse position.
Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y));

// Select the node at the mouse position.
treeView1.SelectedNode = treeView1.GetNodeAt(targetPoint);
}

private void treeView1_DragDrop(object sender, DragEventArgs e)
{
// Retrieve the client coordinates of the drop location.
Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y));

// Retrieve the node at the drop location.
TreeNode targetNode = treeView1.GetNodeAt(targetPoint);

// Retrieve the node that was dragged.
TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));

// Confirm that the node at the drop location is not
// the dragged node or a descendant of the dragged node.
if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
{
// If it is a move operation, remove the node from its current
// location and add it to the node at the drop location.
if (e.Effect == DragDropEffects.Move)
{
draggedNode.Remove();
targetNode.Nodes.Add(draggedNode);
}

// If it is a copy operation, clone the dragged node
// and add it to the node at the drop location.
else if (e.Effect == DragDropEffects.Copy)
{
targetNode.Nodes.Add((TreeNode)draggedNode.Clone());
}

// Expand the node at the location
// to show the dropped node.
targetNode.Expand();
}
}

// Determine whether one node is a parent
// or ancestor of a second node.
private bool ContainsNode(TreeNode node1, TreeNode node2)
{
// Check the parent node of the second node.
if (node2.Parent == null) return false;
if (node2.Parent.Equals(node1)) return true;

// If the parent node is not null or equal to the first node,
// call the ContainsNode method recursively using the parent of
// the second node.
return ContainsNode(node1, node2.Parent);
}

}
一、简介 通过这个课程带大家从零开发一款功能全面的后台管理系统,包括项目搭建、功能实现到最后的Linux系统部署全过程。本课程使用SpringMVC + Spring + Mybatis作为主体框架,使用AdminLTE作为前端框架,使用主流关系型数据库Mysql作为存储数据库,使用非关系型数据库Redis作为缓存数据库,并集成SpringSecuriy安全框架做权限的动态管理,集成Swagger2自动生成接口文档,集成Druid连接池进行SQL性能监控,集成ActiveMQ消息中间件进行异步解耦,提高性能。最后使用linux系统进行服务部署,并搭建nginx反向代理服务器提高网站性能。 二、学习目标 通过本课程的学习带大家掌握SSM框架的开发流程,并熟练使用SpringSecurity做为安全框架进行权限管理,整合相关优秀的开源框架进行功能开发。还在项目中带大家学习前端相关的Jquery、Bootstrap等知识。课程结束之后希望大家能做到独立进行开发项目的目的,增强解决问题的能力,具备功能落地实现的能力。 三、课程涉及知识点 SpringMVC源码分析Mybatis源码分析通用MapperMysql数据库Redis缓存实现ActiveMQ消息中间件SpringSecurity鉴权Swagger2接口文档生成自定义注解AOP切面编程自定义过滤器Logback日志整合Druid性能监控Linux系统Nginx反向代理Ajax异步请求技术Jquery基本使用AdminLTE前端框架Chart图表-线状图和饼状图百度地图定位城市BootStrap前端框架BootStrap-Table插件BootStrap-Treeview插件Markdown编辑器403、404、500错误页面配置数据库事务消息提示插件toastr.js图片上传插件bootstrap fileinput数字滚动效果pv/uv流量统计...四、课程部分内容截图如下 1、首页 2、菜单管理 3、图床管理 4、图标管理 5、留言反馈管理 6、druid监控 7、登录日志

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧