Solved

VB COMBOBOX:  array with the autocomplete matches?

Posted on 2010-08-26
4
720 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:motokent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33531513
To what is your combobox bound ? From where do the items come ?
Are you sure that you want to count each time a character is entered (on_keypress-event) ?
0
 

Author Comment

by:motokent
ID: 33531694
I generate the items in the combobox when the application is started (based on a text file as the data source).

My plan is to check for the number of matches once the (number of characters) > 6.  (Each line has 8 characters.)
Then, if/when there is only one match, I assume that is what the user intends to enter and I process data based on the match.

I can accomplish this by counting the matches in my arraylist that was used to populate the combobox in the beginning, but if I can access the items that autocomplete assigns to the drop-down box, that will save time since autocomplete has already done most of the work for me.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33532139
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

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

Open in new window

0
 

Author Closing Comment

by:motokent
ID: 33532175
Thank you.  This is good.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month6 days, 5 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question