1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
Private Sub listbox1_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean _
, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single _
, ByVal DragState As Long, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
Cancel = True 'autorise la gestion de l'évenement
Effect = 1 'autorise la copie
End Sub
Private Sub listbox1_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean _
, ByVal Action As Long, ByVal Data As MSForms.DataObject, ByVal X As Single _
, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
Dim place As Integer
Cancel = True 'autorise la gestion de l'évenement
Effect = 1 'autorise la copie
Me.ListBox1.RemoveItem Me.ListBox1.ListIndex 'efface la valeur avant de la re-déplacer (évite les doublons)
place = Int(Y / 9) + ListBox1.TopIndex 'calcule le nouvel index de la valeur (9 est la largeur d'un de mes élements de la liste)
If place > ListBox1.ListCount Or Y = Null Then place = ListBox1.ListCount 'si mauvais geste de l'utilisateur on place l'item en dernière position
Me.ListBox1.AddItem Data.GetText, place 'copie de l'item a la nouvelle place
End Sub
Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim MyDataObject As DataObject
Dim Effect As Integer
If Button = 1 Then 'bouton de gauche appuyé
Set MyDataObject = New DataObject
MyDataObject.SetText Me.ListBox1.Value 'mémorisation de la valeur à déplacer
Effect = MyDataObject.StartDrag 'permet la modification du pointeur durant l'opération
Else
If Me.ListBox1.ListCount > 0 Then
Me.ListBox1.ControlTipText = "Déplacement <- possible par glisser-déplacer !"
End If
End If
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim Nom As String
Nom = InputBox("entrer le nouveau nom de la variable" & Chr(13) & Chr(13) & "Libellé actuel : " & ListBox1.Value, "Changement de l'intitulé", ListBox1.Value)
If Nom <> "" Then
ListBox1.List(ListBox1.ListIndex) = Nom
End If
End Sub |
Partager