TreeView 节点拖拽问题之二(分不够可以加)
终于知道怎么查积分了
原来有200多可用分
周六开始就连休5天了
希望之前问题能解决
问题就是
如何实现 按ctrl 或者 shift +单击
选中多个节点
然后拖拽到datagridview里
最好有代码
或者告诉我都在什么事件 用什么属性也行
------解决方案--------------------例子源代码
http://www.java2s.com/Code/CSharp/GUI-Windows-Form/TreeViewDragAndDrop.htm
------解决方案--------------------http://www.codeproject.com/cs/miscctrl/DragDropTreeview.asp?df=100&forumid=84437&exp=0&select=1239364
google可以搜索很多
private void treeView2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
TreeNode newNode;
if (e.Data.GetDataPresent( "System.Windows.Forms.TreeNode ", false))
{
Point pt;
TreeNode destinationNode;
pt = treeView2.PointToClient(new Point(e.X, e.Y));
destinationNode = treeView2.GetNodeAt(pt);
newNode = (TreeNode) e.Data.GetData( "System.Windows.Forms.TreeNode ");
if (!destinationNode.Equals(newNode))
{
//destinationNode.Nodes.Add(newNode.Clone());
destinationNode.Nodes.Add((TreeNode) newNode.Clone());
destinationNode.Expand();
//Remove original node
newNode.Remove();
}
}
}
private void treeView2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void treeView2_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
------解决方案--------------------首先,AllowDrop 设为True;
然后在
private void treeView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
this.DoDragDrop(e.Item,DragDropEffects.Move);
}
///鼠标移动时选中所在坐标的节点
private void treeViewPage_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
Point targetPoint = treeViewPage.PointToClient(new Point(e.X, e.Y));
this.treeViewPage.SelectedNode = this.treeViewPage.GetNodeAt(targetPoint);
}
///然后在这个事件里写你要做什么的代码
private void treeView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
}
------解决方案--------------------给你个例子,自已参照改一下.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim mNode As TreeNode = Me.TreeView1.Nodes.Add( "Fruits ")
mNode.Nodes.Add( "Apple ")
mNode.Nodes.Add( "Peach ")
mNode.Expand()
mNode = Me.TreeView2.Nodes.Add( "Vegetables ")
mNode.Nodes.Add( "Tomato ")
mNode.Nodes.Add( "Eggplant ")
mNode.Expand()
Me.TreeView1.AllowDrop = True
Me.TreeView2.AllowDrop = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
Try
Dim mTree As TreeView = sender
Dim mNode As TreeNode = mTree.GetNodeAt(e.X, e.Y)
mTree.SelectedNode = mNode
If Not mNode Is Nothing Then
mTree.DoDragDrop(mNode.Clone, DragDropEffects.Copy)