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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming autofill for a drop-down list 1

Status
Not open for further replies.

BitCounter

Programmer
Feb 18, 2000
28
US
How do I programmatically execute an &quot;auto-fill&quot; for a drop-down list?<br><br>For example, say I populate a combo-box with the contents of a field from a table.&nbsp;&nbsp;If my table has 100 records and the particular option the user is looking for is 100, then the user has to scroll down (using arrows on combo-box) to the very last item).&nbsp;&nbsp;I would like instead for them to either use the drop-down list and scrolling or if they could begin to type, the box would auto-fill with potential matches as they type.<br><br>Example:&nbsp;&nbsp;User types an C (program responds by completing the box with the first avaible item from combo-box that starts with a C).<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If user then types an a (program responds by completing the box with the first available item from combo-box that starts with a &quot;Ca&quot;).<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;You get the idea..right?&nbsp;&nbsp;Any help at all would be greatly appreciated!<br><br>Renae<br><br>
 
'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 Forum</a><br>
 
Thanks Eric!&nbsp;&nbsp;I'll give that a try.<br><br>&nbsp;&nbsp;Renae
 
Correct me if I'm wrong, but just the mere setting the combo box to 2-DropdownList enables the user to scroll by typing (VB6.0)? ****************
DariceLR
:-{} :-V
****************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top