treeview 拖拽 节点 实现目录的更改

莫凡 2010-01-21 09:18:27
目录如下:

A_奥迪
|____A4L
B_宝马
|____BMW232
|____BMW525


现在如果想通过拖拽treeview节点实现以下结果,希望不吝赐教。

A_奥迪
|____A4L
|____BMW525
B_宝马
|____BMW232

...全文
230 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
莫凡 2010-01-30
  • 打赏
  • 举报
回复
多谢大家,正在解决中。。。
guyehanxinlei 2010-01-27
  • 打赏
  • 举报
回复
收藏一下,顺便帮顶
AddDark 2010-01-26
  • 打赏
  • 举报
回复
帮顶,还真没遇到过这种问题
倒大霉的上帝 2010-01-26
  • 打赏
  • 举报
回复
新建窗体,放置一个Treeview(默认名Treeview1)拷贝下面代码:

Option Explicit
Private mvarSelectKey As String
Private Sub Form_Load()

TreeView1.Indentation = 300 '设置缩进
TreeView1.LineStyle = tvwRootLines '设置显示方式
TreeView1.LabelEdit = tvwManual '不可编辑

TreeView1.Nodes.Add , , "A_aoDi", "A_奥迪" '根节点
TreeView1.Nodes.Add "A_aoDi", tvwChild, "A4L", "A4L" '子节点

TreeView1.Nodes.Add , , "B_baoMa", "B_宝马" '另一个根节点
TreeView1.Nodes.Add "B_baoMa", tvwChild, "B232", "BMW232" ''''
TreeView1.Nodes.Add "B_baoMa", tvwChild, "B525", "BMW525" '''''

Dim msNode As MSComctlLib.Node ''''

For Each msNode In TreeView1.Nodes '展开
msNode.Expanded = True
Next
End Sub

'拖动结束事件
Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)
Dim strHitKey As String
Dim strName As String

strHitKey = TreeView1.HitTest(x, y).Key
strName = TreeView1.Nodes(mvarSelectKey).Text

TreeView1.Nodes.Remove (mvarSelectKey)
TreeView1.Nodes.Add strHitKey, tvwChild, mvarSelectKey, strName

End Sub

'拖动过程事件
Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)

Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
End Sub

'鼠标按下事件
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim strKey As String
If Button = vbLeftButton Then
If Not TreeView1.SelectedItem Is Nothing Then

strKey = TreeView1.SelectedItem.Key

If TreeView1.Nodes(strKey).Children = 0 Then
mvarSelectKey = strKey
TreeView1.DragIcon = TreeView1.SelectedItem.CreateDragImage
TreeView1.Drag vbBeginDrag
End If
End If
End If
End Sub

'鼠标移动事件
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim strKey As String

If Not TreeView1.HitTest(x, y) Is Nothing Then
TreeView1.SelectedItem = TreeView1.HitTest(x, y)
End If

End Sub
Tiger_Zhao 2010-01-25
  • 打赏
  • 举报
回复
http://www.vb-helper.com/howto_treeview_add_node.html
孤独剑_LPZ 2010-01-24
  • 打赏
  • 举报
回复
怎么样了,lz的问题解决了吗
fudonghaiaaaa 2010-01-23
  • 打赏
  • 举报
回复
Option Explicit

Dim mnIndex As Integer ' Holds the index of a Node
Dim mbIndrag As Boolean ' Flag that signals a Drag Drop operation.
Dim moDragNode As Object ' Item that is being dragged.


Private Sub cmdLast_Click()
'Add a node using tvwLast
Dim skey As String
skey = GetNextKey()
On Error GoTo myerr 'if the treeview does not have a node selected
' the next line of code will return an error number 91
TreeView1.Nodes.Add TreeView1.SelectedItem.Index, tvwLast, skey, "Last " & skey, 1, 2
Exit Sub
myerr:
'add a root node in the last postion because no other node is selected.
TreeView1.Nodes.Add , tvwLast, skey, "Last " & skey, 1, 2
Exit Sub
End Sub
Private Sub cmdChild_Click()
'Add a node using tvwChild
Dim oNodex As Node
Dim skey As String
Dim iindex As Integer

On Error GoTo myerr 'if the treeview does not have a node selected
' the next line of code will return an error number 91
iindex = TreeView1.SelectedItem.Index 'Check to see if a Node is selected
skey = GetNextKey() ' Get a key for the new Node
Set oNodex = TreeView1.Nodes.Add(iindex, tvwChild, skey, "Child " & skey, 1, 2)
oNodex.EnsureVisible 'make sure the child node is visible
Exit Sub
myerr:
'Display a messge telling the user to select a node
MsgBox ("You must select a Node to do an Add Child" & vbCrLf _
& "If the TreeView is empty us Add Last to create the first node")
Exit Sub
End Sub
Private Sub Form_Load()
'Add some Nodes so the TreeView is not empty

Dim I As Integer
'在 ImageList 控件中添加一个图象。
Dim oNodex As Object
Dim imgX As ListImage
Dim iindex As Integer
' TreeView1.ImageList = ImageList1 '初始化ImageList。

Set imgX = ImageList1.ListImages.Add(, , LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Tools\APE\Source\Aeservic\SERVICE.ico"))

TreeView1.ImageList = ImageList1 '初始化ImageList。


TreeView1.LineStyle = tvwRootLines

TreeView1.Style = tvwTreelinesPlusMinusPictureText

Dim DriverCount As Integer

Dim GivePath As String

Set moDragNode = Nothing
cmdLast_Click
cmdLast_Click
TreeView1.Nodes(1).Selected = True
cmdChild_Click
End Sub
Private Function GetNextKey() As String
'Returns a new key value for each Node being added to the TreeView
'This algorithm is very simple and will limit you to adding a total of 999 nodes
'Each node needs a unique key. If you allow users to remove Nodes you can't use
'the Nodes count +1 as the key for a new node.

Dim sNewKey As String
Dim iHold As Integer
Dim I As Integer
On Error GoTo myerr
'The next line will return error #35600 if there are no Nodes in the TreeView
iHold = Val(TreeView1.Nodes(1).Key)
For I = 1 To TreeView1.Nodes.Count
If Val(TreeView1.Nodes(I).Key) > iHold Then
iHold = Val(TreeView1.Nodes(I).Key)
End If
Next
iHold = iHold + 1
sNewKey = CStr(iHold) & "_"
GetNextKey = sNewKey 'Return a unique key
Exit Function
myerr:
'Because the TreeView is empty return a 1 for the key of the first Node
GetNextKey = "1_"
Exit Function
End Function



Private 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 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 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_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
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 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
莫凡 2010-01-23
  • 打赏
  • 举报
回复
有没有具体一点的。
  • 打赏
  • 举报
回复
DragDrop事件。
Set DragNode.Parent = .DropHighlight
SYSSZ 2010-01-21
  • 打赏
  • 举报
回复
从哪向哪拖?
莫凡 2010-01-21
  • 打赏
  • 举报
回复
有人帮忙吗。
内容概要:本文系统研究了开关频率大于谐振频率(fs>fr)工况下,移相混合控制LLC谐振变换器在低压增益区域的工作特性,深入分析其在变频与移相结合控制模式下的调制机理、工作模态划分及损耗分布规律。通过Simulink平台构建高保真仿真模型,对变换器在不同负载和输入条件下的电压增益、转换效率、关键器件电压电流应力等性能指标进行了全面仿真验证,重点探讨了其在低增益区间的软开关实现能力与效率优化潜力,旨在提升LLC变换器在宽范围输入输出应用中的动态响应与能源转换效率。; 适合人群:从事电力电子变换器设计、高频电源开发及相关领域的高校研究生、科研院所研究人员及企业研发工程师,要求具备扎实的电路理论基础、电力电子技术知识以及一定的Simulink仿真能力。; 使用场景及目标:①深入理解LLC谐振变换器在fs>fr条件下采用移相混合控制的内在工作机理与模态转换过程;②掌握利用Simulink搭建复杂谐振变换器精确仿真模型的方法与技巧;③分析并优化低压增益区的增益特性与损耗构成,为设计高效率、高功率密度的软开关电源提供理论依据和数据支持; 阅读建议:建议读者结合文中所述仿真模型,亲自复现仿真过程,重点观察不同控制参数(如移相比、开关频率)对电压增益曲线和关键波形的影响,并对比传统变频控制策略,深入探究混合控制在拓宽调压范围、提升轻载效率方面的优势,从而深化对现代高效谐振电源设计的理解。

7,787

社区成员

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

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