如何移动treeview得整个节点(包括子节点)--最好是比较简单得方法

shawls 2003-05-17 10:20:47
如何移动treeview得整个节点(包括子节点)--最好是比较简单得方法

例如:


开始是
abcd
|---abcd1
|------abcd2
|------abcd3
abce
|------abce1
修改后:

abcd
|---abcd2
|------abcd3
|------abcd1
abce
|------abce1

希望速度快,尽量不使用别的存储空间

希望是最快得方法-我知道用递归,先删除,然后慢慢添加,这个方法不好

分,好说,偶有得是

可以:
qq:9181729
mail:shawfile@163.net

参考

http://expert.csdn.net/Expert/topic/1793/1793753.xml?temp=2.647036E-02
...全文
69 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qingming81 2003-06-06
  • 打赏
  • 举报
回复
楼主不要嫌这个方法不好。但一般的文本操作都不太可能如想像的那样移到前面去,都得先读进内存,再往回写。难道拖动节点就会想眼睛看到的那样自动化吗?
qingming81 2003-06-06
  • 打赏
  • 举报
回复
怎么会无法提前?删除所有的节点,按需要再增加一次节点,就可以了。当然,操作时应该小心啊。
fenghanyu 2003-06-06
  • 打赏
  • 举报
回复
up
fenghanyu 2003-05-23
  • 打赏
  • 举报
回复
up
shawls 2003-05-21
  • 打赏
  • 举报
回复
对,没错~
例如:选定一个节点,点击边上的一个按钮,可以实现上下前后的移动(包括子节点)
shawls 2003-05-21
  • 打赏
  • 举报
回复
竟然无法提前,只好就回复了,有人么?up也好啊
shawls 2003-05-20
  • 打赏
  • 举报
回复
不使用拖动,而是一个按钮呢?怎么实现?
online 2003-05-20
  • 打赏
  • 举报
回复
你是说,放置一个按钮,文本框,输入节点,自动移动???????
online 2003-05-18
  • 打赏
  • 举报
回复
有一段代码,你看看
Option Explicit

Private Enum ObjectType
otNone = 0
otFactory = 1
otGroup = 2
otPerson = 3
otFactory2 = 4
otGroup2 = 5
otPerson2 = 6
End Enum

Private SourceNode As Object
Private SourceType As ObjectType
Private TargetNode As Object
' ***********************************************
' Return the node's object type.
' ***********************************************
Private Function NodeType(test_node As Node) As ObjectType
If test_node Is Nothing Then Exit Function
Select Case Left$(test_node.Key, 1)
Case "f"
NodeType = otFactory
Case "g"
NodeType = otGroup
Case "p"
NodeType = otPerson
End Select
End Function
' ***********************************************
' Prepare the ImageList and TreeView controls.
' ***********************************************
Private Sub Form_Load()
Dim i As Integer
Dim factory As Node
Dim group As Node
Dim person As Node

' Load pictures into the ImageList.
For i = 1 To 6
TreeImages.ListImages.Add , , TreeImage(i).Picture
Next i

' Attach the TreeView to the ImageList.
OrgTree.ImageList = TreeImages

' Create some nodes.
Set factory = OrgTree.Nodes.Add(, , "f R & D", "R & D", otFactory, otFactory2)
Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Engineering", "Engineering", otGroup, otGroup2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Cameron, Charlie", "Cameron, Charlie", otPerson, otPerson2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Davos, Debbie", "Davos, Debbie", otPerson, otPerson2)
person.EnsureVisible
Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Test", "Test", otGroup, otGroup2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Able, Andy", "Andy, Able", otPerson, otPerson2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Baker, Betty", "Baker, Betty", otPerson, otPerson2)
person.EnsureVisible

Set factory = OrgTree.Nodes.Add(, , "f Sales & Support", "Sales & Support", otFactory, otFactory2)
Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Showroom Sales", "Showroom Sales", otGroup, otGroup2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Gaines, Gina", "Gaines, Gina", otPerson, otPerson2)
person.EnsureVisible
Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Field Service", "Field Service", otGroup, otGroup2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Helms, Harry", "Helms, Harry", otPerson, otPerson2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Ives, Irma", "Ives, Irma", otPerson, otPerson2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Jackson, Josh", "Jackson, Josh", otPerson, otPerson2)
person.EnsureVisible
Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Customer Support", "Customer Support", otGroup, otGroup2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Klug, Karl", "Klug, Karl", otPerson, otPerson2)
Set person = OrgTree.Nodes.Add(group, tvwChild, "p Landau, Linda", "Landau, Linda", otPerson, otPerson2)
person.EnsureVisible
End Sub
' ***********************************************
' Make the TreeView as large as possible.
' ***********************************************
Private Sub Form_Resize()
OrgTree.Move 0, 0, ScaleWidth, ScaleHeight
End Sub


' ***********************************************
' Save the node pressed so we can drag it later.
' ***********************************************
Private Sub OrgTree_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Set SourceNode = OrgTree.HitTest(x, y)
End Sub

' ***********************************************
' Start a drag if one is not in progress.
' ***********************************************
Private Sub OrgTree_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If SourceNode Is Nothing Then Exit Sub

If Button = vbLeftButton Then
' Start a new drag. Note that we do not get
' other MouseMove events while the drag is
' in progress.

' See what node we are dragging.
SourceType = NodeType(SourceNode)

' Select this node. When no node is highlighted,
' this node will be displayed as selected. That
' shows where it will land if dropped.
Set OrgTree.SelectedItem = SourceNode

' Set the drag icon for this source.
OrgTree.DragIcon = IconImage(SourceType)
OrgTree.Drag vbBeginDrag
End If
End Sub
' ***********************************************
' The user is dropping. See if the drop is valid.
' ***********************************************
Private Sub OrgTree_DragDrop(Source As Control, x As Single, y As Single)
If SourceNode Is Nothing Then Exit Sub

If Not (OrgTree.DropHighlight Is Nothing) Then
' It's a valid drop. Set source node's
' parent to be the target node.
Set SourceNode.Parent = OrgTree.DropHighlight
Set OrgTree.DropHighlight = Nothing
End If

Set SourceNode = Nothing
SourceType = otNone
End Sub
' ***********************************************
' The mouse is being dragged over the control.
' Highlight the appropriate node.
' ***********************************************
Private Sub OrgTree_DragOver(Source As Control, x As Single, y As Single, State As Integer)
Dim target As Node
Dim highlight As Boolean

If SourceNode Is Nothing Then Exit Sub

' See what node we're above.
Set target = OrgTree.HitTest(x, y)

' If it's the same as last time, do nothing.
If target Is TargetNode Then Exit Sub
Set TargetNode = target

highlight = False
If Not (TargetNode Is Nothing) Then
' See what kind of node were above.
If NodeType(TargetNode) + 1 = SourceType Then _
highlight = True
End If

If highlight Then
Set OrgTree.DropHighlight = TargetNode
Else
Set OrgTree.DropHighlight = Nothing
End If
End Sub

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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