Question : VB COMBOBOX:  array with the autocomplete matches?

I am using a combobox with auto-complete enabled.  At runtime, when the text changes I would like to count the number of matches.  If there is only one match, then I'll take some action (without user having to hit "enter", or do anything else).  Is there a collection or array that contains the matches?  It would have the same items that get displayed in the drop-down.

Answer : VB COMBOBOX:  array with the autocomplete matches?

You can use the code below. Just call in your keypress-event

Dim searchString As String = "t"

Dim countItems As Integer = ComboBox1.Items.Cast(Of String).ToList().FindAll(New PredicateWrapper(Of String, String)(searchString, AddressOf IsItemValid)).Count
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:
in your keypress
... onkey_press(....)
Dim searchString As String = "t"

Dim countItems As Integer = ComboBox1.Items.Cast(Of String).ToList().FindAll(New PredicateWrapper(Of String, String)(searchString, AddressOf IsItemValid)).Count

end sub


    Function IsItemValid(ByVal item As String, ByVal argument As String) As Boolean
        Return item.StartsWith(argument)
    End Function


    Public Delegate Function PredicateWrapperDelegate(Of T, A)(ByVal item As T, ByVal argument As A) As Boolean
    Public Class PredicateWrapper(Of T, A)
        Private _argument As A
        Private _wrapperDelegate As PredicateWrapperDelegate(Of T, A)
        Public Sub New(ByVal argument As A, ByVal wrapperDelegate As PredicateWrapperDelegate(Of T, A))
            _argument = argument
            _wrapperDelegate = wrapperDelegate
        End Sub
        Private Function InnerPredicate(ByVal item As T) As Boolean
            Return _wrapperDelegate(item, _argument)
        End Function
        Public Shared Widening Operator CType(ByVal wrapper As PredicateWrapper(Of T, A)) As Predicate(Of T)
            Return New Predicate(Of T)(AddressOf wrapper.InnerPredicate)
        End Operator
    End Class
Random Solutions  
 
programming4us programming4us