Spinbutton pour changer l'ordre d'une listbox multi colonnes

  • Initiateur de la discussion Initiateur de la discussion lowkick
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

lowkick

XLDnaute Nouveau
Bonjour,

J'utilise des spinbuttons pour changer l'ordre des items d'une listbox, mais je n'arrive pas adapter celui ci pour qu'il fonctionne sur une listbox multi colonnes . Est-ce que quelqu'un pourrais m'aider ?


Code:
Private Sub SpinButton1_SpinUp()
If Liste_ouvr_PRO.ListCount = 0 Then Exit Sub
If Liste_ouvr_PRO.ListIndex = 0 Then Exit Sub
Dim s As String
Dim n As Integer
n = Liste_ouvr_PRO.ListIndex
s = GetItemText(n - 1)
Liste_ouvr_PRO.RemoveItem n - 1
Liste_ouvr_PRO.AddItem s, n
End Sub

Private Sub SpinButton1_SpinDown()
If Liste_ouvr_PRO.ListCount = 0 Then Exit Sub
If Liste_ouvr_PRO.ListIndex = Liste_ouvr_PRO.ListCount - 1 Then Exit Sub
Dim s As String
Dim n As Integer
n = Liste_ouvr_PRO.ListIndex
s = GetItemText(n + 1)
Liste_ouvr_PRO.RemoveItem n + 1
Liste_ouvr_PRO.AddItem s, n
End Sub

Private Function GetItemText(i As Integer) As String
GetItemText = Liste_ouvr_PRO.List(i)
End Function
 
Dernière édition:
Re : Spinbutton pour changer l'ordre d'une listbox multi colonnes

bonsoir,
il faut initialiser t1 à l'ouverture du formulaire et le déclarer en tête du module
Code:
Dim t1

Private Sub UserForm_Initialize()
t1 = Liste_ouvr_PRO.List
End Sub

Private Sub SpinButton1_SpinUp()
x = Liste_ouvr_PRO.ListIndex
If Liste_ouvr_PRO.ListCount = 0 Then Exit Sub
If x <= 0 Then Exit Sub
For i = 0 To Liste_ouvr_PRO.ColumnCount - 1
    t1(x, i) = Liste_ouvr_PRO.List(x - 1, i)
    t1(x - 1, i) = Liste_ouvr_PRO.List(x, i)
Next
Liste_ouvr_PRO.List = t1
Liste_ouvr_PRO.ListIndex = x - 1
End Sub

Private Sub SpinButton1_SpinDown()
x = Liste_ouvr_PRO.ListIndex
If Liste_ouvr_PRO.ListCount = 0 Then Exit Sub
If x = Liste_ouvr_PRO.ListCount - 1 Then Exit Sub
For i = 0 To Liste_ouvr_PRO.ColumnCount - 1
    t1(x, i) = Liste_ouvr_PRO.List(x + 1, i)
    t1(x + 1, i) = Liste_ouvr_PRO.List(x, i)
Next
Liste_ouvr_PRO.List = t1
Liste_ouvr_PRO.ListIndex = x + 1
End Sub

A+
kjin
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
10
Affichages
300
Réponses
2
Affichages
218
  • Question Question
Microsoft 365 Problème de date
Réponses
5
Affichages
171
  • Question Question
Microsoft 365 Erreur UBound
Réponses
4
Affichages
151
Retour