CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2001
    Posts
    23

    Comboboxwith auto select help please !

    I would be very grateful if someone could give me some ideas about this one :

    I want to have a combobox on a form that a user can type a value into. The list attached to it will be populated with various common responses that they may select. Is there any way for me to automatically select the item as they are typing? For example, lets imagine it was a list of colours. If the user typed a B could BLUE appear in the box and then if the user carried on and type a R after the B could BROWN appear ? Do you get the gist ? Many thanks.


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Comboboxwith auto select help please !

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

    Const CB_ERR = -1
    Const CB_FINDSTRING = &H14C


    'Add the sub

    Sub sMatchEntry(cbo As ComboBox, KeyAscii As Integer)
    Dim sBuffer As String
    Dim lRetVal As Long

    sBuffer = Left(cbo.Text, cbo.SelStart) & Chr(KeyAscii)
    lRetVal = SendMessage((cbo.hWnd), CB_FINDSTRING, _
    -1, ByVal sBuffer)
    If lRetVal <> CB_ERR Then
    With cbo
    .ListIndex = lRetVal
    .Text = .List(lRetVal)
    .SelStart = Len(sBuffer)
    .SelLength = Len(.Text)
    End With
    KeyAscii = 0
    End If
    End Sub

    ' in the KeyPress Event of the Combobox, add:

    Private Sub Combo1_KeyPress(KeyAscii As Integer)
    sMatchEntry Combo1, KeyAscii
    End Sub"





    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured