Results 1 to 5 of 5

Thread: dropdown combobox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    23
    Is there any way to raise a event that would drop down the combo box as a user types with the closest match highligted

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    Maybe this is what you need?

    paste this into a form that has a combobox called MyCombo:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
       ComboExtendedUI(MyCombo) = True
    
       With MyCombo
          .AddItem "Aepfel"
          .AddItem "spatzen"
          .AddItem "Aerger"
          .AddItem "gieskanne"
          .AddItem "flasche"
          .AddItem "uhr"
          .AddItem "Ananas"
          .AddItem "wandschrand"
          .AddItem "Ameise"
          .AddItem "computer"
          .AddItem "Aroma"
          .AddItem "ordner"
          .AddItem "akten"
          .AddItem "datum"
          .AddItem "bambus"
       End With
    End Sub
    
    Private Sub MyCombo_GotFocus()
        SendKeys "{DOWN}"
    End Sub
    
    Private Sub MyCombo_KeyPress(KeyAscii As Integer)
       KeyAscii = AutoFind(MyCombo, KeyAscii, False)
    End Sub

    this goes into a module:
    Code:
    Option Explicit
    
    Const CB_GETEXTENDEDUI = &H156
    Const CB_SETEXTENDEDUI = &H155
    Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Long, ByVal wMsg As Long, _
        ByVal wParam As Long, ByVal lParam As Long) _
       As Long
    '--------------------------------------------------------------------------------
    
    Const CB_FINDSTRING = &H14C
    Const CB_ERR = (-1)
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Long, ByVal wMsg As Long, _
        ByVal wParam As Long, lParam As Any) _
       As Long
    '--------------------------------------------------------------------------------
    Public Property Let ComboExtendedUI(ByRef cboThis As ComboBox, ByVal bState As Boolean)
        ' Set whether combo box drops down using the Down Arrow or not:
        SendMessageLong cboThis.hwnd, CB_SETEXTENDEDUI, Abs(bState), 0
    End Property
    
    Public Property Get ComboExtendedUI(ByRef cboThis As ComboBox) As Boolean
        ' Get whether combo box drops down using the Down Arrow or not:
        ComboExtendedUI = (SendMessageLong(cboThis.hwnd, CB_GETEXTENDEDUI, 0, 0) <> 0)
    End Property
    '--------------------------------------------------------------------------------
    
    Public Function AutoFind(ByRef cboCurrent As ComboBox, _
                             ByVal KeyAscii As Integer, _
                             Optional ByVal LimitToList As Boolean = False)
            
    Dim lCB As Long
    Dim sFindString As String
    
    On Error GoTo Err_Handler
        If KeyAscii = 8 Then
            If cboCurrent.SelStart <= 1 Then
                cboCurrent = ""
                AutoFind = 0
                Exit Function
            End If
            If cboCurrent.SelLength = 0 Then
                sFindString = UCase(Left(cboCurrent, Len(cboCurrent) - 1))
            Else
                sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart - 1)
            End If
        ElseIf KeyAscii < 32 Or KeyAscii > 255 Then
            Exit Function
        Else
            If cboCurrent.SelLength = 0 Then
                sFindString = UCase(cboCurrent.Text & Chr$(KeyAscii))
            Else
                sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart) & Chr$(KeyAscii)
            End If
        End If
        lCB = SendMessage(cboCurrent.hwnd, CB_FINDSTRING, -1, ByVal sFindString)
    
        If lCB <> CB_ERR Then
            cboCurrent.ListIndex = lCB
            cboCurrent.SelStart = Len(sFindString)
            cboCurrent.SelLength = Len(cboCurrent.Text) - cboCurrent.SelStart
            AutoFind = 0
        Else
            If LimitToList = True Then
                AutoFind = 0
            Else
                AutoFind = KeyAscii
            End If
        End If
            
    Err_Handler:
    
    End Function
    hope, this helps

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    if the info in the list is in a database then this will work also:

    Code:
    Private Sub txtCity_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode <> 8 And Len(txtCity.Text) > 1 And Shift = 0 Then
    pWord = txtCity.Text
    On Error GoTo nomatch
    deTracker.rstbCmns.Filter = "City Like '" & pWord & "*'"
    deTracker.rstbCmns.MoveFirst
    txtCity.Text = txtCity.Text & Mid(deTracker.rstbCmns!City, Len(pWord) + 1, Len(deTracker.rstbCmns!City))
    txtCity.SelStart = Len(pWord)
    txtCity.SelLength = Len(txtCity.Text) - Len(pWord)
    nomatch:
    ElseIf Shift = 1 Then
    txtCity.SelStart = Len(pWord)
    txtCity.SelLength = Len(txtCity.Text) - Len(pWord)
    End If
    End Sub
    txtCity being a textbox (although it should work with anything)
    deTracker being the data environment
    rstbCmns is the command recordset with the list in it

    [Edited by Edneeis on 09-01-2000 at 03:33 AM]

  4. #4
    Lively Member
    Join Date
    Jul 2000
    Location
    Australia
    Posts
    69

    Unhappy

    I like the above code..I was hoping to us it with data Combo, not to sure how to modify it for example datacontrols don't have listindex. Can you show me how to use the code on datacontrols

    Gerard
    Live long and prosper...

  5. #5
    Lively Member
    Join Date
    May 2000
    Posts
    70

    Cool

    Have you tried setting the following in the properties of data combo?

    MatchEntry = 1 dblEntendedMatching
    Style = 2 dbcDropDownList

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