首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

treeview控件node拖动的有关问题

2012-02-06 
treeview控件node拖动的问题!node节点如下所示,我现在想拖动122222时将122222变成第一级的node,有什么方法

treeview控件node拖动的问题!
node节点如下所示,我现在想拖动122222时将122222变成第一级的node,有什么方法可以做到吗?


11111 第一级
  122222 第二级
  133333 第三级

21111 一级
  222222 二级
  233333 三级

31111 一级
  32222 二级
  33333 三级




[解决办法]
删除这个条目,一级位置插入一个
事件DragDrop、DragOver、MouseMove等里判断
[解决办法]


Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)
' 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
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 mark 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 Sub

Private 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 Sub

Private 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 Sub


Private Sub WriteChild(ByVal iNodeIndex As Integer)
' Write the child nodes to the table. This sub uses recursion
' to loop through the child nodes. It receives the Index of
' the node that has the children
Dim I As Integer
Dim iTempIndex As Integer
iTempIndex = TreeView1.Nodes(iNodeIndex).Child.FirstSibling.Index
'Loop through all a Parents Child Nodes
For I = 1 To TreeView1.Nodes(iNodeIndex).Children
mRS.AddNew
mRS("parent") = TreeView1.Nodes(iTempIndex).Parent.Key
mRS("key") = TreeView1.Nodes(iTempIndex).Key
mRS("text") = TreeView1.Nodes(iTempIndex).Text
mRS("image") = TreeView1.Nodes(iTempIndex).Image
mRS("selectedimage") = TreeView1.Nodes(iTempIndex).SelectedImage
mRS.Update
' If the Node we are on has a child call the Sub again
If TreeView1.Nodes(iTempIndex).Children > 0 Then
WriteChild (iTempIndex)
End If
' If we are not on the last child move to the next child Node


If I <> TreeView1.Nodes(iNodeIndex).Children Then
iTempIndex = TreeView1.Nodes(iTempIndex).Next.Index
End If
Next I
End Sub

热点排行