以下是在Tree View下的Drag & Drop的程式,但問題是當選了一個Node之後並開始Drag時,整個Tree View Area也同時Drag。請問這是甚麼緣故?
Private Sub tvIGD_DragDrop(Source As Control, x As Single, y As Single)
'If no Node is highlighted then get out
If tvIGD.DropHighlight Is Nothing Then
bDropFlag = False
  Exit Sub
Else
'If dropping on itself then get out
  If xNode = tvIGD.DropHighlight Then
    Text1.Text = "Cannot drop itself"
    Exit Sub
  End If
  If Mid$(tvIGD.DropHighlight.Key, 1, 3) = "LV2" Then
    'Assign an element to the group
    Call sAddNode
  End If
  Set tvIGD.DropHighlight = Nothing
  bDropFlag = False
End If
End Sub
Private Sub tvIGD_DragOver(Source As Control, x As Single, y As Single, State As Integer)
Dim xTempNode As Node
If bDropFlag Then
'Set DropHighLight to the mouse's coordinates only
  'if the node is a group type
  Set xTempNode = tvIGD.HitTest(x, y)
  If Not xTempNode Is Nothing Then
    If Mid$(xTempNode.Key, 1, 3) = "LV2" Then  'It is a Group
      Set tvIGD.DropHighlight = xTempNode
    End If
  End If
End If
End Sub

Private Sub tvIGD_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'Set the item being dragged
Set xNode = tvIGD.SelectedItem
End Sub
Private Sub tvIGD_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim sTempNode As Node
'Signal a Drag operation
If Button = vbLeftButton Then
'Only allow dragging if it is an element
  Set sTempNode = tvIGD.HitTest(x, y)
  If Not sTempNode Is Nothing Then
    If Mid$(sTempNode.Key, 1, 3) = "LV1" Then  'It is an element
      bDropFlag = True  'Set the flag to true
      tvIGD.Drag vbBeginDrag 'Drag operation
    End If
  End If
End If
End Sub
文章標籤
全站熱搜
創作者介紹
創作者 vbqa 的頭像
vbqa

小吳 VBQA 程式設計討論

vbqa 發表在 痞客邦 留言(0) 人氣(40)