Exercice Visual Basic : ListBox
Rédigé par GC Team, Publié le 07 Janvier 2012, Mise à jour le Jeudi, 12 Août 2021 22:57![](/images/thumb/146/default.png)
Participez au vote ☆☆☆☆☆★★★★★
Ecrire le code VB qui permet de réaliser l'interface suivante:
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 |
Public Class Form1 Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged TextBox3.Text = ListBox1.Items.Count TextBox4.Text = ListBox1.SelectedIndex TextBox5.Text = ListBox1.Text End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ListBox1.Items.Clear() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Add(TextBox1.Text) TextBox1.Text = "" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Val(TextBox2.Text) <= ListBox1.Items.Count - 1 Then ListBox1.SelectedIndex = CInt(TextBox2.Text) Else MsgBox("L'élément rechercher est introuvable!") End If End Sub End Class |