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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
Private Sub Cbo1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cbo1.TextChanged
With Cbo1
'Trie par ordre alphabetique
.Sorted = True
If .FindString(.Text) > 0 Then
search = .Text.Length
.SelectedIndex = .FindString(.Text)
.SelectionStart = search
.SelectionLength = .Text.Length - search
Dim lastSearch As String
Dim lastIndex As Integer = -1
Dim searchText As String = Cbo1.Text.Trim()
Dim lvItem As ListViewItem = Nothing
'Pas de recherche vide
If searchText = "" Then
Return
End If
'nettoyer items sélectionnés
If (ListV1.SelectedItems.Count > 0) Then
ListV1.SelectedItems(0).Selected = False
End If
If searchText = lastSearch And lastIndex < ListV1.Items.Count - 1 Then
lvItem = ListV1.FindItemWithText(searchText, False, lastIndex + 1)
Else
'Lancer la recherche depuis le Debut
lvItem = ListV1.FindItemWithText(searchText, False, 0)
End If
lastSearch = searchText
If Not (lvItem Is Nothing) Then
lastIndex = lvItem.Index
ListV1.Focus()
lvItem.Selected = True
ListV1.TopItem = lvItem
End If
End If
End With
End Sub |
Partager