treeview节点拖拽
在拖动树节点到目标节点处的时候,如何给目标节点添加标识(比如,在目标节点的前面或后面显示分隔符) ? --------------------编程问答-------------------- 节点拖动的功能已经实现。求有关于给目标节点添加标识的解决源码? --------------------编程问答-------------------- 能贴你节点拖动的代码来学习学习么。。。。 --------------------编程问答--------------------用js树形菜单写。。。。
自己看看哪个更适合。。。
--------------------编程问答--------------------
private void button1_Click(object sender, EventArgs e)
{
TreeNode Node = treeView1.SelectedNode;
TreeNode PrevNode = Node.PrevNode;
if (PrevNode != null)
{
TreeNode NewNode = (TreeNode)Node.Clone();
if (Node.Parent == null)
{
treeView1.Nodes.Insert(PrevNode.Index, NewNode);
}
else
{
Node.Parent.Nodes.Insert(PrevNode.Index, NewNode);
}
Node.Remove();
treeView1.SelectedNode = NewNode;
}
}
private void button2_Click(object sender, EventArgs e)
{
TreeNode Node = treeView1.SelectedNode;
TreeNode NextNode = Node.NextNode;
if (NextNode != null)
{
TreeNode NewNode = (TreeNode)Node.Clone();
if (Node.Parent == null)
{
treeView1.Nodes.Insert(NextNode.Index + 1, NewNode);
}
else
{
Node.Parent.Nodes.Insert(NextNode.Index + 1, NewNode);
}
Node.Remove();
treeView1.SelectedNode = NewNode;
}
}
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("System.Windows.Forms.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;
TreeNode targeNode;
pt = ((TreeView)(sender)).PointToClient(new Point(e.X, e.Y));
targeNode = this.treeView1.GetNodeAt(pt);
//如果目标节点无子节点则添加为同级节点,反之添加到下级节点的未端
TreeNode NewMoveNode = (TreeNode)moveNode.Clone();
if (targeNode.Nodes.Count == 0)
{
targeNode.Parent.Nodes.Insert(targeNode.Index, NewMoveNode);
}
else
{
targeNode.Nodes.Insert(targeNode.Nodes.Count, NewMoveNode);
}
//更新当前拖动的节点选择
treeView1.SelectedNode = NewMoveNode;
//展开目标节点,便于显示拖放效果
targeNode.Expand();
//移除拖放的节点
moveNode.Remove();
}
补充:.NET技术 , C#