Private Sub CommandButton1_click() Dim Buffer As String, Idx as Long Idx = List1.ListIndex If Idx >0 Then With List1 Buffer = .List(Idx-1) .List(Idx-1) = .List(Idx) .List(Idx) = Buffer End With End If
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Form1 Private Idx As Integer Public Property List1 As Object Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) End Sub Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click End Sub Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) End Sub Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click End End Sub Private Sub CommandButton2_click(sender As Object, e As EventArgs) Handles Button2.Click Dim Buffer As String, Idx As Long Idx = List1.Index If Idx > 0 Then With List1 Buffer = .List(Idx - 1) .Selected(Idx - 1) = True .List(Idx - 1) = .List(Idx) .List(Idx) = Buffer End With End If End Sub Private Sub ListBox1_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged End Sub End Class
Public Property List1 As Object: cette ligne ne doit pas être là ! List1 est la listbox qui est posée sur la Form : c'est un contrôle et nom une variable Property de classe !.
Me.Close()suffit largement
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Public Class Form1 ' http://www.dreamincode.net/forums/topic/155775-move-items-up-and-down-in-listbox/ 'Up Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click If ListBox1.SelectedIndex > 0 Then Dim I = ListBox1.SelectedIndex - 1 ListBox1.Items.Insert(I, ListBox1.SelectedItem) ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) ListBox1.SelectedIndex = I End If End Sub 'Down Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then Dim I = ListBox1.SelectedIndex + 2 ListBox1.Items.Insert(I, ListBox1.SelectedItem) ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) ListBox1.SelectedIndex = I - 1 End If End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim i As Integer For i = 1 To 100 ListBox1.Items.Add(i.ToString) Next i End Sub End Class
If List1.ListIndex < List1.ListCount - 1 Then List1.ListIndex = List1.ListIndex + 1
If List1.ListIndex > 0 Then List1.ListIndex = List1.ListIndex - 1
If List1.selectedIndex < List1.items.count - 1 Then List1.selectedIndex = List1.selectedIndex + 1pour descendre et
If List1.selectedIndex > 0 Then List1.selectedIndex = List1.selectedIndex - 1