The .NET Developer Community
Sign in
|
Join
|
Help
Home
Blogs
Forums
FAQ
Wikis
Members
Search
Services
Forums
»
Archived Forums
»
VB6 Newbies
»
Intellisense with combo boxes
Intellisense with combo boxes
rated by 0 users
This post has 2 Replies | 1 Follower
Beth Peterson
Montana
Since 1/7/2003
Posts
2
Reputation
25
Reply
Beth Peterson
(
Beth Peterson
)
Posted: 1/7/2003 12:16 PM
rated by 0 users
How can I code to allow more than 1 character to be input into the text portion of a combo box and automatically scroll to the closest match in the drop down list? I want to duplicate the autoexpand property of a combo box in Access.
| Post Points: 20
XTab
Scotland
Since 2/21/2002
Posts
11,074
Reputation
120,073
Reply
Ged Mead
(
XTab
)
replied on
1/7/2003 2:55 PM
rated by 0 users
This is close (but maybe no cigar ?? :D ) It will find the first match from the first character onwards and is reasonably intelligent - but not totally foolproof.
Oh, and as it stands it doesn't drop down the combo but puts the nearest match in the Combo "Caption" (text) box, but I think this could be worked round with a bit of a tweak.
You need this in a BAS Module
Code:
Option Explicit
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 Const CB_FINDSTRING = &H14C
and something like this in a form will show how it goes:
Code:
Option Explicit
Private Sub Form_Load()
With Combo1
.AddItem "Return"
.AddItem "Set"
.AddItem "Returned"
.AddItem "Settee"
.AddItem "Setter"
.AddItem "Settee Back"
End With
End Sub
Private Sub Combo1_Change()
Dim iStart As Integer
Dim sString As String
Static iLeftOff As Integer
iStart = 1
iStart = Combo1.SelStart
If iLeftOff <> 0 Then
Combo1.SelStart = iLeftOff
iStart = iLeftOff
End If
sString = CStr(Left(Combo1.Text, iStart))
Combo1.ListIndex = SendMessage(Combo1.hwnd, _
CB_FINDSTRING, -1, ByVal CStr(Left( _
Combo1.Text, iStart)))
If Combo1.ListIndex = -1 Then
iLeftOff = Len(sString)
Combo1.Text = sString
End If
Combo1.SelStart = iStart
iLeftOff = 0
End Sub
HTH
I don't claim authorship, BTW, but thought it was very good when I spotted it a while back.
XTab
| Post Points: 5
Beth Peterson
Montana
Since 1/7/2003
Posts
2
Reputation
25
Reply
Beth Peterson
(
Beth Peterson
)
replied on
1/7/2003 3:34 PM
rated by 0 users
I got this resolved, thanks for your help. :D
| Post Points: 5
< Previous Topic
|
Next Topic >
Page 1 of 1 (3 items) |
RSS
Copyright 1998-2017 vbCity.com LLC