dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4,VB5,VB6
Expertise: Intermediate
Aug 19, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


ComboBoxExtendedMatching - Extended Matching mode for ComboBox controls

' Enable extended matching to any type combobox control
'
' Extended matching means that as soon as you type in the edit area
' of the ComboBox control, the routine searches for a partial match 
' in the list area and highlights the characters left to be typed.
'
' To enable this capability you have only to call this routine
' from within the KeyPress routine of the ComboBox, as follows:
'
' Private Sub Combo1_KeyPress(KeyAscii As Integer)
'    ComboBoxExtendedMatching Combo1, KeyAscii
' End Sub

Sub ComboBoxExtendedMatching(cbo As ComboBox, KeyAscii As Integer, _
    Optional CompareMode As VbCompareMethod = vbTextCompare)
    Dim index As Long
    Dim Text As String
    
    ' if user pressed a control key, do nothing
    If KeyAscii <= 32 Then Exit Sub
    
    ' produce new text, cancel automatic key processing
    Text = Left$(cbo.Text, cbo.SelStart) & Chr$(KeyAscii) & Mid$(cbo.Text, _
        cbo.SelStart + 1 + cbo.SelLength)
    KeyAscii = 0
    
    ' search the current item in the list
    For index = 0 To cbo.ListCount - 1
        If InStr(1, cbo.List(index), Text, CompareMode) = 1 Then
            ' we've found a match
            cbo.ListIndex = index
            Exit For
        End If
    Next
    
    ' if no matching item
    If index = cbo.ListCount Then
        cbo.Text = Text
    End If
    
    ' highlight trailing chars in the edit area
    cbo.SelStart = Len(Text)
    cbo.SelLength = 9999
    
End Sub

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date