Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

DragDrop de listView vers treeView

1 réponse
Avatar
Gerald
Bonjour,
est-ce qqun aurait un exemple de drag'n drop d'un listview vers un treeView
?

Merci

Gerald

1 réponse

Avatar
Picalausa François
"Gerald" a écrit dans le message de news:
%23sC$
est-ce qqun aurait un exemple de drag'n drop d'un listview vers un
treeView



Hello,

Voici un exemple:
Option Explicit

Private Sub Form_Load()
'A définir en design time
ListView1.OLEDragMode = ccOLEDragAutomatic

Dim i As Long

For i = 1 To 20
ListView1.ListItems.Add , , CStr(i)
Next i

End Sub

'(Optionnel; default = copie)
Private Sub ListView1_OLECompleteDrag(Effect As Long)
'Supprime l'item de la liste
ListView1.ListItems.Remove ListView1.SelectedItem.Index
End Sub

'(Optionnel; default = copie)
Private Sub ListView1_OLEStartDrag(Data As MSComctlLib.DataObject,
AllowedEffects As Long)
'Indique qu'on ne peut que déplacer l'item
AllowedEffects = OLEDropEffectConstants.vbDropEffectMove
End Sub

Private Sub TreeView1_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As
Long, Button As Integer, Shift As Integer, x As Single, y As Single)
'Retrouve l'item sur lequel notre item a été droppé
Dim TreeNode As Node

Set TreeNode = TreeView1.HitTest(x, y)

If Not TreeNode Is Nothing Then
'Ajoute un noeud root
TreeView1.Nodes.Add TreeNode, TreeRelationshipConstants.tvwChild, ,
Data.GetData(vbCFText)
TreeNode.Expanded = True
Else
'Ajoute un noeud root
TreeView1.Nodes.Add , , , Data.GetData(vbCFText)
End If
End Sub

Pour plus d'infos, voir:
http://msdn.microsoft.com/library/en-us/vbcon98/html/vbconoledragdrop.asp

--
Picalausa François