Results 1 to 2 of 2

Thread: VB6 - Auto Complete Combo Box.

  1. #1

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    VB6 - Auto Complete Combo Box.

    Here is little snippet I put together for a project that will give you Auto Complete feature in your Project. Simply Place a Combo Box named cmbInput and add a reference to "Microsoft Scripting Runtime".

    Note that I only used FSO to load some sample(I am loading all the folder name from C:\program files) item to the combo box, you can add any item you wish.

    Finally, i am looping through all Item to find the match, if I use API it might be faster. I will see if I can speed it up in future when I get a chance.

    Enjoy

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmbInput_KeyUp(KeyCode As Integer, Shift As Integer)
    4.     AutoSel cmbInput, KeyCode
    5. End Sub
    6.  
    7.  
    8. Private Sub Form_Load()
    9.    
    10.     Dim FolderPath As String
    11.     FolderPath = "C:\Program Files"
    12.    
    13.     Dim Folder
    14.     Dim File
    15.    
    16.     Dim FSO As New Scripting.FileSystemObject
    17.    
    18.     Set Folder = FSO.GetFolder(FolderPath)
    19.    
    20.     Dim f
    21.  
    22.    
    23.     For Each f In Folder.SubFolders
    24.         cmbInput.AddItem f.Name
    25.     Next
    26.    
    27. End Sub
    28.  
    29. Function AutoSel(Cmb As ComboBox, KeyCode As Integer)
    30.    
    31.     Debug.Print KeyCode
    32.  
    33.     If KeyCode = vbEnter Then Exit Function
    34.     If KeyCode = 8 Then Exit Function    'Backspace
    35.     If KeyCode = 37 Then Exit Function  'left key
    36.     If KeyCode = 38 Then Exit Function 'up arrow key
    37.     If KeyCode = 39 Then Exit Function  'right key
    38.     If KeyCode = 40 Then Exit Function  'down arrow key
    39.     If KeyCode = 46 Then Exit Function  'delete key
    40.     If KeyCode = 33 Then Exit Function  'page up key
    41.     If KeyCode = 34 Then Exit Function  'page down key
    42.     If KeyCode = 35 Then Exit Function  'end key
    43.     If KeyCode = 36 Then Exit Function  'home key
    44.    
    45.    
    46.     Dim Text As String
    47.     Text = Cmb.Text
    48.    
    49.     Dim i As Long
    50.     Dim Temp As String
    51.    
    52.    
    53.     For i = 0 To Cmb.ListCount
    54.         Temp = Left(Cmb.List(i), Len(Text))
    55.         If LCase(Temp) = LCase(Text) Then
    56.             Cmb.Text = Cmb.List(i)
    57.             Cmb.ListIndex = i
    58.             Cmb.SelStart = Len(Text)
    59.             Cmb.SelLength = Len(Cmb.List(i))
    60.             'Cmb.SetFocus
    61.         End If
    62.     Next
    63.    
    64. End Function
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  2. #2
    New Member
    Join Date
    Sep 2012
    Posts
    2

    Re: VB6 - Auto Complete Combo Box.

    Awesome!!!great work
    but how to add autocomplete in textbox in vb6 from database i.e ACCESS
    Hope u will reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width