We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,047 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Autocomplete Textbox

Hi all,
I searching for how to make autocomplete in textbox.
however there are list contain fruits name.
"Apple"
"Banana"
"Pear"
"Orange"
When i type "Ap" in textbox, program will completed the text and highlight the fruit name in listbox.
How i can do this.

Thank you

2
Contributors
3
Replies
38 Minutes
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
ITKnight
Light Poster
48 posts since Jan 2008
Reputation Points: 11
Solved Threads: 1
Skill Endorsements: 0

See if this helps :

Option Explicit

#If Win32 Then
    Private Const LB_FINDSTRING = &H18F
    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

#Else

    Private Const WM_USER = &H400
    Private Const LB_FINDSTRING = (WM_USER + 16)
    Private Declare Function SendMessage Lib _
                    "User" (ByVal hWnd As Integer, ByVal _
                    wMsg As Integer, ByVal wParam As _
                    Integer, lParam As Any) As Long
#End If

Private Sub Form_Load()
    List1.AddItem "Orange"
    List1.AddItem "Banana"
    List1.AddItem "Apple"
    List1.AddItem "Pear"
End Sub

Private Sub Text1_Change()
    Dim pos As Long
    List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))

    If List1.ListIndex = -1 Then
        pos = Text1.SelStart
    Else
        pos = Text1.SelStart
        Text1.Text = List1
        Text1.SelStart = pos
        Text1.SelLength = Len(Text1.Text) - pos
    End If

End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    On Error Resume Next
    If KeyCode = 8 Then 'Backspace
        If Text1.SelLength <> 0 Then
            Text1.Text = Mid$(Text1, 1, Text1.SelStart - 1)
            KeyCode = 0
        End If
    ElseIf KeyCode = 46 Then 'Del
        If Text1.SelLength <> 0 And _
            Text1.SelStart <> 0 Then
            Text1.Text = ""
            KeyCode = 0
        End If
    End If
End Sub
Jx_Man
Senior Poster
3,529 posts since Nov 2007
Reputation Points: 1,488
Solved Threads: 521
Skill Endorsements: 64

Wow...it's working like a charm..
thank you jx_man.

ITKnight
Light Poster
48 posts since Jan 2008
Reputation Points: 11
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Jx_Man

You're Welcome. :)

Jx_Man
Senior Poster
3,529 posts since Nov 2007
Reputation Points: 1,488
Solved Threads: 521
Skill Endorsements: 64

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0594 seconds using 2.63MB