OVH Cloud OVH Cloud

Ordre dans ListBox

2 réponses
Avatar
JCM
Bonjour

Est-il possible après avoir sélectionné une ligne dans une ListBox la
remonter ou la descendre à l'aide d'un bouton.
Ex : passez le texte de la ligne 8 en postion 3

Un bout de code serait sympa
Merci d'avance
Cordialement
JCM

2 réponses

Avatar
ng
Salut,


Voici un exemple déplacant l'item 8 en 3 :

Private Sub Command1_Click()
Call MoveItem(List1, 2, 7)
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 8
List1.AddItem "Item #" & i
Next
End Sub

Public Sub MoveItem(oList As ListBox, wSource As Integer, wDest As Integer)
Dim strTemp As String
strTemp = oList.List(wSource)
oList.List(wSource) = oList.List(wDest)
oList.List(wDest) = strTemp
strTemp = ""
End Sub

Voici un exemple permetant de monter/descndre l'item sélectionné (il n'y a
aucun controle d'erreur) :

Private Sub Command1_Click()
Call MoveItem(List1, List1.ListIndex, List1.ListIndex - 1)
List1.ListIndex = List1.ListIndex - 1
End Sub

Private Sub Command2_Click()
Call MoveItem(List1, List1.ListIndex, List1.ListIndex + 1)
List1.ListIndex = List1.ListIndex + 1
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 8
List1.AddItem "Item #" & i
Next
End Sub

Public Sub MoveItem(oList As ListBox, wSource As Integer, wDest As Integer)
Dim strTemp As String
strTemp = oList.List(wSource)
oList.List(wSource) = oList.List(wDest)
oList.List(wDest) = strTemp
strTemp = ""
End Sub


--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

JCM wrote:
Bonjour

Est-il possible après avoir sélectionné une ligne dans une ListBox la
remonter ou la descendre à l'aide d'un bouton.
Ex : passez le texte de la ligne 8 en postion 3

Un bout de code serait sympa
Merci d'avance
Cordialement
JCM


Avatar
JCM
Salut

un merci tardif pour ton aide, c'est OK

Cordialement
JCM

"ng" a écrit :

Salut,


Voici un exemple déplacant l'item 8 en 3 :

Private Sub Command1_Click()
Call MoveItem(List1, 2, 7)
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 8
List1.AddItem "Item #" & i
Next
End Sub

Public Sub MoveItem(oList As ListBox, wSource As Integer, wDest As Integer)
Dim strTemp As String
strTemp = oList.List(wSource)
oList.List(wSource) = oList.List(wDest)
oList.List(wDest) = strTemp
strTemp = ""
End Sub

Voici un exemple permetant de monter/descndre l'item sélectionné (il n'y a
aucun controle d'erreur) :

Private Sub Command1_Click()
Call MoveItem(List1, List1.ListIndex, List1.ListIndex - 1)
List1.ListIndex = List1.ListIndex - 1
End Sub

Private Sub Command2_Click()
Call MoveItem(List1, List1.ListIndex, List1.ListIndex + 1)
List1.ListIndex = List1.ListIndex + 1
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 8
List1.AddItem "Item #" & i
Next
End Sub

Public Sub MoveItem(oList As ListBox, wSource As Integer, wDest As Integer)
Dim strTemp As String
strTemp = oList.List(wSource)
oList.List(wSource) = oList.List(wDest)
oList.List(wDest) = strTemp
strTemp = ""
End Sub


--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

JCM wrote:
> Bonjour
>
> Est-il possible après avoir sélectionné une ligne dans une ListBox la
> remonter ou la descendre à l'aide d'un bouton.
> Ex : passez le texte de la ligne 8 en postion 3
>
> Un bout de code serait sympa
> Merci d'avance
> Cordialement
> JCM