乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      添加treeview的節(jié)點拖拽功能

       悟靜 2009-07-18

      自己動手寫程序,想添加什么功能就添加什么,真是很爽。
      因為我用的access數(shù)據(jù)庫保存資料,在自動讀入treeview控件中時,為了解決讀入的先后順序,我給每個記錄添加了一個divid字段,比如根節(jié)點是0,一級是1,二級是2,依次類推,所以拖拽是必須考慮修改該字段,實現(xiàn)起來復(fù)雜了一些,現(xiàn)在我按照拖拽實現(xiàn)的順序編程如下:

      Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
      mybutton = Button
      If Button = vbLeftButton And Shift Then
      Set sourcenode = TreeView1.SelectedItem '設(shè)置拖動的源 對象,全局node對象
      sourcedivid = txtdivid
      Set TreeView1.DropHighlight = Nothing
      'DropHighlight 返回或設(shè)置一個Node對象或ListItem對象的引用。該對象在鼠標(biāo)移到其上時使用系統(tǒng)加亮顏色加亮。
      End If
      End Sub
      Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
      StatusBar1.Panels(1).Text = "請及時保存。"
      If Button = vbLeftButton And Shift Then
      dragnow = True   
      TreeView1.DragIcon = TreeView1.SelectedItem.CreateDragImage ‘定義拖拽顯示的圖標(biāo),必須的。
      TreeView1.Drag vbBeginDrag   ’開始
      End If
      End Sub
      Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
      If dragnow = True Then
      ' Set DropHighlight to the mouse's coordinates.
      Set TreeView1.DropHighlight = TreeView1.HitTest(x, y) ‘注意既使目標(biāo)高亮,又是設(shè)置目標(biāo)對象
      End If
      End Sub
      Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)’拖放后的目標(biāo)操作
      Dim parentkey As String
      Dim parentdivid As Integer
      Set mcctree = DataEnvironment1.rsCommand2

      If TreeView1.DropHighlight Is Nothing Then '如果目標(biāo)為空,不操作
      dragnow = False
      Exit Sub
      Else ' Set dragged node's parent property to the target node.
      On Error GoTo checkerror ' To prevent circular errors.
      If MsgBox("你確定要把[" & sourcenode.Text & "]移動到[" & TreeView1.DropHighlight.Text & "]下嗎? ", vbOKCancel) = vbCancel Then Exit Sub

      If TreeView1.DropHighlight.Text = "我的文檔" Then '因為數(shù)據(jù)庫里沒有該記錄,所以如果目標(biāo)是放到根節(jié)點下,則需要單獨處理
      parentkey = "root"
      parentdivid = 1
      mcctree.find "title='" & sourcenode.Text & "'", , , adBookmarkFirst
      mcctree.Fields("relative") = parentkey ’修改數(shù)據(jù)庫
      mcctree.Fields("divid") = parentdivid
      mcctree.Update
      Set sourcenode.Parent = TreeView1.DropHighlight ‘這里是修改treeview的節(jié)點位置的關(guān)鍵代碼。 Else
      mcctree.find "title='" & TreeView1.DropHighlight.Text & "'", , , adBookmarkFirst
      If mcctree.Fields("key") = "" Then '如果目標(biāo)不是節(jié)點,則放棄
      MsgBox "非節(jié)點不能放置", vbInformation
      Set mcctree = Nothing
      Exit Sub
      End If
      ‘如果既不是根節(jié)點也不是資料則如下處理
      Set sourcenode.Parent = TreeView1.DropHighlight
      mcctree.find "title='" & sourcenode.Parent.Text & "'", , , adBookmarkFirst ’查父節(jié)點
      parentkey = mcctree.Fields("key").Value
      parentdivid = mcctree.Fields("divid").Value
          If CInt(txtdivid) + 1 = sourcedivid Then '如果是同級別,則只要改relative
          mcctree.find "title='" & sourcenode.Text & "'", , , adBookmarkFirst
          mcctree.Update "relative", parentkey
          Debug.Print "ok111", parentkey
          Else ‘否則要改relative 和divid兩個字段的值
          mcctree.find "title='" & sourcenode.Text & "'", , , adBookmarkFirst
          Debug.Print parentkey, parentdivid + 1
          mcctree.Fields("relative") = parentkey
          mcctree.Fields("divid") = parentdivid + 1
          mcctree.Update
          updatechildnod mcctree.Fields("key").Value, mcctree.Fields("divid").Value ’遞歸子函數(shù)
          End If
      End If
      Cls '清除
      Set TreeView1.DropHighlight = Nothing
      dragnow = False
      Set mcctree = 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."
      If MsgBox(msg, vbExclamation & vbOKCancel) = vbOK Then
      dragnow = False
      Set TreeView1.DropHighlight = Nothing
      Set mcctree = Nothing
      Exit Sub
      End If
      Else
      Set mcctree = Nothing
      Debug.Print Err.Description
      End If
      Exit Sub
      End Sub

      Private Sub updatechildnod(nodekey As String, nodedivid As Integer) ‘遞歸子函數(shù)
      Dim upcctree As ADODB.Recordset
      Dim nkey() As String   ’動態(tài)數(shù)組
      Dim ndivid() As Integer
      Dim i As Integer
      Dim x As Integer
      i = 0
      If DataEnvironment1.rsCommand4.State = 1 Then ’因為每次都要關(guān)閉記錄對象所以遞歸要變通。
      DataEnvironment1.rsCommand4.Close
      End If

      DataEnvironment1.rsCommand4.Open "select * from cctree where [relative]= '" & nodekey & "'"
         x = DataEnvironment1.rsCommand4.RecordCount ‘根據(jù)關(guān)鍵字查找子對象
         If x > 0 Then
         ReDim nkey(x)   ’定義一個臨時數(shù)組保存需要遞歸處理的字節(jié)點對象,
         ReDim ndivid(x) ‘因為子節(jié)點對象不會超過符合條件的記錄數(shù),重定義數(shù)組
         Set upcctree = DataEnvironment1.rsCommand4
         upcctree.MoveFirst   ‘到第一條
         Do   ’循環(huán)
         Debug.Print upcctree.Fields("divid").Value, upcctree.Fields("title").Value
         upcctree.Update "divid", nodedivid + 1 ‘子節(jié)點只要更新divid
         If upcctree.Fields("key").Value <> "" Then
         nkey(i) = upcctree.Fields("key").Value ’如果是子節(jié)點,暫時不處理,保存到數(shù)組中
         ndivid(i) = upcctree.Fields("divid").Value
         i = i + 1
         End If
         'Debug.Print upcctree.Fields("divid").Value, upcctree.Fields("title").Value
         upcctree.MoveNext    ‘繼續(xù)處理下一條
         Loop While Not upcctree.EOF ’這樣本層節(jié)點下的所有對象都已修改,下面可以處理再下一級
          If i <> 0 Then    ‘判斷是否有這樣的節(jié)點
      For x = 0 To i - 1
      updatechildnod nkey(x), ndivid(x)   ’遞歸
      Next
      End If
         Set upcctree = Nothing
         End If
      End Sub

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多