|
-
Sep 26th, 2003, 01:10 PM
#1
Thread Starter
Fanatic Member
Search as we go
Have a text box and a list view..
need to enter letters in text box and have names in list box
move up as I type... Any ideas?
Thanks
-
Sep 26th, 2003, 01:11 PM
#2
Hyperactive Member
Re: Search as we go
Could you be little more clear??? What do u mean by: need to enter letters in text box and have names in list box ???
-
Sep 26th, 2003, 01:14 PM
#3
Thread Starter
Fanatic Member
list box contains a list of names first and last from db
want to implement a "soft-seek"...
If I enter n in text box..I would like items with names that start with letter n to popup and so on...
Thanks
-
Sep 26th, 2003, 01:26 PM
#4
Hyperactive Member
This is a code I have for now for a combobox. If I enter "East" for example, I would bring all the addresses that start with E then EA then EAS then EAST narrowing the list as I continues. change cmboMyCombo to the name of your combo box.. also make sure the style property is set to 0. I guess this can get u at start as to how to work for ur problem....I am in office right now and do not have VB on my machine to give a working example. Since u said u want the data from database...u need to connect to backend before using the code. Then in your code u should always loop thru the backend for the results.
I hope this gets u a start..
VB Code:
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
Private Const CB_FINDSTRING = &H14C
Private Const CB_ERR = (-1)
Private Function AutoComplete(ByRef CB As ComboBox, ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
Dim FindMatch As Long
Dim ComboEntry As String
On Error GoTo ErrRtn
If KeyAscii = 8 Then
If CB.SelStart <= 1 Then
CB.Text = ""
AutoComplete = 0
Exit Function
End If
If CB.SelLength = 0 Then
ComboEntry = UCase(Left(CB, Len(CB) - 1))
Else
ComboEntry = Left$(CB.Text, CB.SelStart - 1)
End If
ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
Exit Function
Else
If CB.SelLength = 0 Then
ComboEntry = UCase(CB.Text & Chr$(KeyAscii))
Else
ComboEntry = Left$(CB.Text, CB.SelStart) & Chr$(KeyAscii)
End If
End If
FindMatch = SendMessage(CB.hWnd, CB_FINDSTRING, -1, ByVal ComboEntry)
If FindMatch <> CB_ERR Then
CB.ListIndex = FindMatch
CB.SelStart = Len(ComboEntry)
CB.SelLength = Len(CB.Text) - CB.SelStart
AutoComplete = 0
Else
If LimitToList = True Then
AutoComplete = 0
Else
AutoComplete = KeyAscii
End If
End If
Exit Function
ErrRtn:
AutoComplete = 0
End Function
Private Sub cmboMyCombo_KeyPress(KeyAscii as Integer)
KeyAscii = AutoCompelte(cmboMyCombo,KeyAscii,True)
End Sub
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
|