|
-
Aug 27th, 2003, 08:17 AM
#1
Thread Starter
New Member
Autocomplete
All,
I'm very new to VB and and learning very rapidly due to the knowledge on this site. I have a question/problem that I hope someone can help me out with.
I have a text box and a list view on a form. I would like to give the user the option of typing text into the text box and use an autocomplete functionality that would search the list view and find the first item in it with the string entered. As the user types more text it would keep searching the list view based upon the new string entered.
I have seen a few postings on this site through searching but have not found enough to get started.
All help would be greatly appreciated.
Thanks again from a beginner.
-
Aug 27th, 2003, 01:01 PM
#2
Here is a function that I found and modified for auto type ahead on a combo box.
It works great.
This may help you.
Code:
Option Explicit
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const CB_FINDSTRING = &H14C
Public Function AutoFind(ByRef cboCtl As ComboBox, ByRef KeyAscii As Integer, Optional ByRef LimitToList As Boolean = False)
'<RR 05/08/03 - VB/OUTLOOK GURU>
On Error GoTo No_Bugs
Dim lCB As Long
Dim sFindString As String
If KeyAscii = 8 Then
If cboCtl.SelStart <= 1 Then
cboCtl = ""
AutoFind = 0
Exit Function
End If
If cboCtl.SelLength = 0 Then
sFindString = UCase(Left(cboCtl, Len(cboCtl) - 1))
Else
sFindString = Left$(cboCtl.Text, cboCtl.SelStart - 1)
End If
ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
Exit Function
Else
If cboCtl.SelLength = 0 Then
sFindString = UCase(cboCtl.Text & Chr$(KeyAscii))
Else
sFindString = Left$(cboCtl.Text, cboCtl.SelStart) & Chr$(KeyAscii)
End If
End If
lCB = SendMessageStr(cboCtl.hwnd, CB_FINDSTRING, -1, ByVal sFindString)
If lCB <> (-1) Then
cboCtl.ListIndex = lCB
cboCtl.SelStart = Len(sFindString)
cboCtl.SelLength = Len(cboCtl.Text) - cboCtl.SelStart
AutoFind = 0
Else
If LimitToList = True Then
AutoFind = 0
Else
AutoFind = KeyAscii
End If
End If
Exit Function
No_Bugs:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, App.ProductName
End Function
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|