si tu peux m’écrire le code
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionListBox.sorted = true
vider un tableau d'entier dans une listbox
' ' Bonjour badano, ' ' Voici le code testé, rajoute les objets ' Option Explicit On Public Class Form1 Dim tableauDentiers(20) As Integer ' commence à 0 mais j n'utilise pas, donc commence à 1 Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ' pour tester -> remplissage de listBox1 avec des nombres entiers positifs Dim i As Integer Dim hasard As Integer ListBox1.Items.Clear() For i = 1 To 20 Randomize() hasard = Int((2012 - 1 + 1) * Rnd() + 1) ListBox1.Items.Add(hasard) Next i End Sub Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown Dim i As Integer ' remplissage du tableau d'entier Dim j As Integer Dim trans As Integer Dim t As String = "" For i = 1 To 20 tableauDentiers(i) = 0 Next i For i = 0 To 19 tableauDentiers(i + 1) = ListBox1.Items(i) Next i ' ' vide ( COPIE ) le tableau d'entiers dans listbox2 ListBox2.Items.Clear() For i = 1 To 20 ListBox2.Items.Add(tableauDentiers(i)) Next i ' ' tri le tableau d'entiers par ordre croissant ' la listBox pzut trier en mettant la propriété sorted = True ' ListBox2.Sorted = True For i = 1 To 20 For j = 1 To 19 If tableauDentiers(j) > tableauDentiers(j + 1) Then trans = tableauDentiers(j) tableauDentiers(j) = tableauDentiers(j + 1) tableauDentiers(j + 1) = trans End If Next j Next i For i = 1 To 20 t = t & tableauDentiers(i) & vbLf Next i MsgBox(t) End Sub ' ' Cordialement, Joe ' End Class
Dim arr1() ReDim arr1(ListBox1.Items.Count - 1) ListBox1.Items.CopyTo(arr1, 0)
ListBox1.DataSource = ListArray