Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

节点拖曳示例

qiecaiban  发表于:2016-02-05 12:15:33  
复制

按照

【Access小品】TreeView节点拖曳示例   http://www.accessoft.com/article-show.asp?id=8938

来做

感觉好像节点可以拖动

但是实际上好像动不过去。


有谁知道为什么?

谁给解释一下

 

Top
煮江品茶 发表于:2016-02-05 14:09:49
用劲拖

qiecaiban 发表于:2016-02-05 14:24:51


qiecaiban 发表于:2016-02-05 14:26:12
Option Compare Database
Option Explicit


Private SourceNode As node  '定??点?曳的源?点
Private TargetNode As node  '定??点?曳的目??点
Private Sub Form_Load()
    Call SetTree(Me.xTree.Object, "a0")
End Sub


Private Sub SetTree(ByVal tree As TreeView, ByVal Parentkey As String)
    Dim id As Long, str As String
    Dim rs As New ADODB.Recordset
    Dim ssql As String
    Dim i As Long
    Dim node As node
    
    str = Left(Parentkey, 1)      '取父?点key的第一个字符
    id = Val(Mid(Parentkey, 2))   '取父?点key中的ParentID?
    
    If id = 0 Then
        xTree.Nodes.Clear
        Set node = xTree.Nodes.Add(, , Parentkey, "産品目録")
        node.Expanded = True
    End If
    
    ssql = "select * from 3 WHERE ParentID = " & id
    rs.Open ssql, CurrentProject.Connection, adOpenStatic, adLockReadOnly
    For i = 1 To rs.RecordCount
        str = Chr(Asc(str) + 1)    '字母?增一位
        Set node = tree.Nodes.Add(Parentkey, tvwChild, str & rs!id.Value, rs!Name.Value)
        Call SetTree(tree, str & rs!id.Value)
        rs.MoveNext
    Next
    
    rs.Close: Set rs = Nothing
    Set node = Nothing
    
End Sub


Private Sub xTree_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
    Set SourceNode = Me.xTree.HitTest(x, y)
    If SourceNode Is Nothing = False Then
        If Button = 1 Then
            Set Me.xTree.SelectedItem = SourceNode
        End If
    End If
End Sub


Private Sub xTree_OLEDragOver(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
    Dim target As node
    Set target = Me.xTree.HitTest(x, y)
    
    If target Is TargetNode Then Exit Sub
    If target Is Nothing Then Exit Sub
    If target Is SourceNode Then Exit Sub
    If isEldershipNode(SourceNode, target) Then Exit Sub
    
    Set TargetNode = target
    Set Me.xTree.DropHighlight = TargetNode
    
End Sub


Private Function isEldershipNode(NodeA As node, NodeB As node) As Boolean
    '功能:判断NodeA是否?NodeB的前??点
    If NodeB.Parent Is Nothing Then
        isEldershipNode = False  '如果?点B?根?点,那??点A不是?点B的前??点
    ElseIf NodeB.Parent.Key = NodeA.Key Then
        isEldershipNode = True
    Else
        isEldershipNode = isEldershipNode(NodeA, NodeB.Parent)  '???用
    End If
   
End Function


Private Sub xTree_OLEDragDrop(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim ssql As String
    If Me.xTree.DropHighlight Is Nothing = False Then
        ssql = "update tblType set ParentID=" & Val(Mid(TargetNode.Key, 2))
        ssql = ssql & " where ID=" & Val(Mid(SourceNode.Key, 2))
        CurrentDb.Execute ssql
        Call SetTree(Me.xTree.Object, "a0")
    End If

End Sub


代码这样

是不是代码那里有错误?



qiecaiban 发表于:2016-02-05 14:27:34
感觉能拖  其实拖不过去。

大海 发表于:2016-02-05 16:55:23

煮江品茶老师!

你的代码就是注释太少了。



总记录:5篇  页次:1/1 9 1 :