• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

search in combo

I have combo box. Style-DropDown list.
When I press the letter, I get first item in combo wich starts with this letter. But List of items is really big, and I want to allow user to select item by typing in multiple letters.
1 Solution
Below is a routine that I have not yet incorporated into a class (where it would be best reused!).  I created this a while ago, and use it in almost every program I write.  The basic idea is this:

1) After populating the combo or list or whatever list source you have, call the CreateIntellisense routine.  It will concatenate all possibilities into a string.

2) In the Change event of the combo box (or text box, etc.), place the code in in the cboDataType_Change() stub.

Change any reference to cboDataType to whatever the name of your ComboBox is.  Good luck.

Private strIntelliSense As String
Private blnBackSpace As Boolean

Private Sub cboDataType_Change()
    Dim intSelStart As Integer
    Dim intInstr As Integer
    Static intInside As Integer
    intInside = intInside + 1 'Stop recursive calls
    If intInside = 1 And blnBackSpace = False And cboDataType.Text <> "" Then
        intInstr = InStr(UCase(strIntelliSense), "{" & UCase(Left(Me.cboDataType, Me.cboDataType.SelStart)))
        If intInstr Then
            intSelStart = Me.cboDataType.SelStart
            Me.cboDataType.Text = Mid(strIntelliSense, intInstr + 1, InStr(Mid(strIntelliSense, intInstr), "}") - 2)
            Me.cboDataType.SelStart = intSelStart
            Me.cboDataType.SelLength = Len(Me.cboDataType.Text) - intSelStart
        End If
    End If
    blnBackSpace = False
    intInside = intInside - 1
End Sub

Private Sub CreateIntellisense()
    Dim intCounter As Integer
    strIntelliSense = ""
    For intCounter = 0 To cboDataType.ListCount - 1
        strIntelliSense = strIntelliSense & "{" & Me.cboDataType.List(intCounter) & "}"
End Sub

monaxAuthor Commented:
Thank you taplin, it's working fine.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now