Solved

VB COMBOBOX:  array with the autocomplete matches?

Posted on 2010-08-26
4
715 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Format Transaction Number 19 50
How to embed a manual into my vb 2005 project 7 26
why PtrSafe before Function on 64bit does not fix the APIs? 2 30
VB .net 2010 Byte array 2 24
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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