Appelez simplement à plusieurs reprises ListBox.FindString() jusqu'à ce que vous les ayez tous trouvés. Par exemple:
Public Class Form1
Public Sub New()
InitializeComponent()
ListBox1.SelectionMode = SelectionMode.MultiExtended
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListBox1.BeginUpdate()
ListBox1.SelectedIndices.Clear()
If TextBox1.Text.Length > 0 Then
Dim index As Integer = -1
Do
dim found As integer = ListBox1.FindString(TextBox1.Text, index)
If found <= index Then Exit Do
ListBox1.SelectedIndices.Add(found)
index = found
Loop
End If
ListBox1.EndUpdate()
End Sub
End Class
Si vous avez besoin de trouver une correspondance sur une partie de la zone de liste chaîne de l'article, vous pouvez chercher les articles comme celui-ci:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListBox1.BeginUpdate()
ListBox1.SelectedIndices.Clear()
If TextBox1.Text.Length > 0 Then
For index As Integer = 0 To ListBox1.Items.Count - 1
Dim item As String = ListBox1.Items(index).ToString()
If item.IndexOf(TextBox1.Text, StringComparison.CurrentCultureIgnoreCase) >= 0 Then
ListBox1.SelectedIndices.Add(index)
End If
Next
End If
ListBox1.EndUpdate()
End Sub