改变treeview中的节点顺序和层次,就像VB菜单编辑器中左右箭头改变层次一样,不过还要加上上下改变节点顺序,请高手解答,我的笨方法,去掉该节点,放到他该去的位置,但是如果该节点又很多子节点就很麻烦,请高手提供好的方案,明天交工就差这个了,急切等待
改变treeview中的节点顺序和层次,就像VB菜单编辑器中左右箭头改变层次一样,不过还要加上上下改变节点顺序,请高手解答,我的笨方法,去掉该节点,放到他该去的位置,但是如果该节点又很多子节点就很麻烦,请高手提供好的方案,明天交工就差这个了,急切等待
' If user didn't move mouse or released it over an invalid area.If TreeView1.DropHighlight Is Nothing Then
mbIndrag = False
Exit Sub
Else
' Set dragged node's parent property to the target node.
On Error GoTo checkerror ' To prevent circular errors.
Set moDragNode.Parent = TreeView1.DropHighlight
Cls
Print TreeView1.DropHighlight.Text & _
" is parent of " & moDragNode.Text
' Release the DropHighlight reference.
Set TreeView1.DropHighlight = Nothing
mbIndrag = False
Set moDragNode = Nothing
Exit Sub ' Exit if no errors occured.
End If
checkerror:
' Define constants to represent Visual Basic errors code.
Const CircularError = 35614
If Err.Number = CircularError Then
Dim msg As String
msg = "A node can't be made a child of its own children."' Display the message box with an exclamation icon
' and with OK and Cancel buttons.
If MsgBox(msg, vbExclamation & vbOKCancel) = vbOK Then
' Release the DropHighlight reference.
mbIndrag = False
Set TreeView1.DropHighlight = Nothing
Exit Sub
End If
End If
End SubPrivate Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
If mbIndrag = True Then
' Set DropHighlight to the mouse's coordinates.
Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
End If
End SubPrivate Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
'Make sure we are over a Node
If Not TreeView1.DropHighlight Is Nothing Then
'Set the Node we are on to be the selected Node
'if we don't do this it will not be the selected node
'until we finish clicking on the Node
TreeView1.SelectedItem = TreeView1.HitTest(x, y)
Set moDragNode = TreeView1.SelectedItem ' Set the item being dragged.
End If
Set TreeView1.DropHighlight = Nothing
End SubPrivate Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then ' Signal a Drag operation.
mbIndrag = True ' Set the flag to true.
' Set the drag icon with the CreateDragImage method.
TreeView1.DragIcon = TreeView1.SelectedItem.CreateDragImage
TreeView1.Drag vbBeginDrag ' Drag operation.
End IfEnd Sub
其他类似了 Set nodeDst = TreeView2.SelectedItem
Set nodetemp = nodeDst.Next
Set nodetemp2 = TreeView2.Nodes.Add(nodetemp.index, tvwNext, GetNextKey(), nodeDst.Text, nodeDst.Image, nodeDst.SelectedImage)
MoveNode nodeDst, nodetemp2