Results 1 to 3 of 3

Thread: [RESOLVED] comboBox keypress

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2009
    Posts
    66

    Resolved [RESOLVED] comboBox keypress

    hi.. is it possible.. when i type a letter "S" all the records begins with "S" will be shown or highlighted? its like when you register in a website.. in choosing country section.. thanks

  2. #2
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: comboBox keypress

    Are you talking about "Type Ahead Ability" or are you talking about running a query against records based upon input?

    Type Ahead Ability
    Code:
    Option Explicit
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LB_FINDSTRING = &H18F 'for listboxes
    Private Const CB_FINDSTRING = &H14C 'for comboboxes
    
    Private Sub Form_Load()
    Combo1.AddItem "this is a test", 0
    Combo1.AddItem "so is this", 1
    Combo1.AddItem "but not this", 2
    Combo1.AddItem "Well really it is", 3
    Combo1.AddItem "in fact", 4
    Combo1.AddItem "all of this", 5
    Combo1.AddItem "is a test", 6
    End Sub
    
    Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
    
    Dim Idx As Long, TempString As String
    
    If KeyCode < 32 Or KeyCode > 126 Then Exit Sub
    
    If KeyCode = vbKeyBack Then Exit Sub
    
    TempString = Combo1.Text
    
    Idx = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal TempString)
    
    If Idx <> -1 Then
      Combo1.ListIndex = Idx
      Combo1.SelStart = Len(TempString)
      Combo1.SelLength = Len(Combo1.Text) - Len(TempString)
    Else
      Combo1.Text = TempString
      Combo1.SelStart = Len(TempString)
    End If
    
    End Sub
    Good Luck
    Option Explicit should not be an Option!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2009
    Posts
    66

    Re: comboBox keypress

    thank you very much.. your code rocks!!! another additional to my collections..

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