Treeview拖曳

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值