Results 1 to 4 of 4

Thread: ListBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    South Africa
    Posts
    3

    Post

    I want to type in the first letter of a word and the rest of the word must appear automatically as I type it in the list box or combo box(Like when you try to enter a URL and it appears automatically and choose it from the list of options given).Please help.

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    There's probably a better way but I just knocked this up for you...

    Code:
    Option Explicit
    
    Dim strInput As String
    Private Sub Combo1_Change()
    
      Dim i As Integer
      Dim match As Boolean
      match = False
      
      If strInput <> "" Then
        For i = 0 To Combo1.ListCount - 1
        If Left(Combo1.List(i), Len(strInput)) = strInput Then
          Combo1.ListIndex = i
          match = True
        End If
        Next
      End If
      
      If Not match Then
        Combo1.Text = strInput
      End If
      
    
    Combo1.SelStart = Len(strInput)
    Combo1.SelLength = Len(Combo1.Text) - Len(strInput)
    End Sub
    
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
    On Error Resume Next
    
    If KeyAscii >= 32 And KeyAscii <= 126 Then
      strInput = strInput & Chr(KeyAscii)
    End If
    If KeyAscii = 8 Then
      strInput = Left(strInput, Len(strInput) - 1)
    End If
    
    
    End Sub
    
    Private Sub Form_Load()
    Combo1.AddItem "aaaaa"
    Combo1.AddItem "bbbcceeedd"
    Combo1.AddItem "bbbaa"
    
    End Sub
    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company



  3. #3
    Guest

    Post

    You can try to use the SendMessage api.

    Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal 1hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long

    Const LB_FINDSTRING = &H18F

    Private Sub Text_Change()
    List.ListIndex = SendMessage(List.hWnd, LB_FINDSTRING, -1, ByVal Text.Text)
    End Sub

    -Kayoca Mortation

  4. #4
    Addicted Member
    Join Date
    Jan 2000
    Location
    BC, Canada
    Posts
    142

    Post

    For combo control, set style to dropdown list, it will do what you want, I didn't try listbox, it may work too! Goodluck!

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