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


Tip of the Day
Language: Visual Basic
Expertise: Advanced
Jan 8, 2001

ComboBox Autofill


ComboBox controls, out of the box, don't help complete phrases as they are typed in. The sample code below accomplishes that task. cmb is the name of the ComboBox to which Autofill is added. mbNoManualChange is a modular level variable used as a status flag, preventing the UpdateText routine from raising the control's change event (avoiding circular references). mbNoManualChange also blocks Autofill when Delete or Backspace keys are used.
 
     Dim mbNoManualChange As Boolean

     Private Sub cmb_Change()
         On Error GoTo Routine_Error

         If Not mbNoManualChange Then UpdateText

     Routine_Error:
         If Err.Number <> 0 Then
             MsgBox Err.Description, vbInformation, Err.Sourc
             Err.Clear
         End If
     End Sub

     Private Sub cmb_KeyDown(KeyCode As Integer, Shift As Integer)
         On Error GoTo Routine_Error

         Select Case KeyCode
             Case vbKeyDelete, vbKeyBack: mbNoManualChange = True
             Case Else: mbNoManualChange = False
         End Select

     Routine_Error:
         If Err.Number <> 0 Then
             MsgBox Err.Description, vbInformation, Err.Sourc
             Err.Clear
         End If
     End Sub

     Private Sub UpdateText()
         On Error GoTo Routine_Error

         Dim sTypedText As String
         Dim sSelectText As String
         Dim lCounter As Long

         'Suspend Status
         mbNoManualChange = True

         'Update Combobox Text
         With cmb
             sTypedText = Replace(.Text, .SelText, 
Nazmul Siddiqui
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap