Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
GB
Does anyone know the property to set the combo box to 'autoexpand'. In Access theres an autoexpand property which automatically fills the combo box with the remaining charachters that te user has inputed.<br>
<br>
With VB it only seems to bring up the value with the first letter that you typed in (catch my drift?)<br>
<br>
Thanks for any help
 
'Add a module to your project (In the menu choose Project -&gt; Add Module, Then click Open)<br>
'Add 1 Combo Box to your form. Set the Combo Box Style property to 2 - DropDown List.<br>
'Add few items to the Combo Box list, some of them should begin with the same character.<br>
'When you will press a key, the first item that begins with the key you pressed will be selected.<br>
'If you will press the same key again, the second item that begins with the key you pressed <br>
'will be selected.<br>
'Insert the following code to the module :<br>
<br>
Dim strCombo As String<br>
Const WM_SETREDRAW = &HB<br>
Const KEY_A = 65<br>
Const KEY_Z = 90<br>
Declare Function SendMessage Lib &quot;User32&quot; (ByVal hWnd As Integer, ByVal wMsg As _<br>
Integer, ByVal wParam As Integer, lParam As Any) As Long<br>
<br>
'Insert the following code to your form:<br>
<br>
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)<br>
Dim x%<br>
Dim strTemp$<br>
Dim nRet&<br>
If KeyCode &gt;= KEY_A And KeyCode &lt;= KEY_Z Then<br>
'only look at letters A-Z<br>
strTemp = Combo1.Text<br>
If Len(strTemp) = 1 Then strCombo = strTemp<br>
nRet& = SendMessage(Combo1.hWnd, WM_SETREDRAW, False, 0&)<br>
For x = 0 To (Combo1.ListCount - 1)<br>
If UCase((strTemp & Mid$(Combo1.List(x), Len(strTemp) + 1))) = UCase(Combo1.List(x)) Then<br>
Combo1.ListIndex = x<br>
Combo1.Text = Combo1.List(x)<br>
Combo1.SelStart = Len(strTemp)<br>
Combo1.SelLength = Len(Combo1.Text) - (Len(strTemp))<br>
strCombo = strCombo & Mid$(strTemp, Len(strCombo) + 1)<br>
Exit For<br>
Else<br>
If InStr(UCase(strTemp), UCase(strCombo)) Then<br>
strCombo = strCombo & Mid$(strTemp, Len(strCombo) + 1)<br>
Combo1.Text = strCombo<br>
Combo1.SelStart = Len(Combo1.Text)<br>
Else<br>
strCombo = strTemp<br>
End If<br>
End If<br>
Next<br>
nRet& = SendMessage(Combo1.hWnd, WM_SETREDRAW, True, 0&)<br>
End If<br>
End Sub<br>
<br>
<p>Eric De Decker<br><a href=mailto:vbg.be@vbgroup.nl>vbg.be@vbgroup.nl</a><br><a href= Visual Basic Center</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top