Advanced Auto Complete List Combo and List Boxs
This is a high class code article
i never be stingy with vb lovers .
I try and success to move the power of access to the power of vb .
The main features are :
1) the sub can be used with combo box and list box controls.
2) High performance.
3) faster with huge lists.
4) fully support of Delete and Backspace keys.
5)Case Sensitive.
6) of course few lines of code point to the purpose.
Try it and tell me.
If you found this really advanced please be faithful and vote.
Thanks.
Original Author: Said Sowiny
Code
'================================== Public Sub AutoCompleteList(ByVal cboCtl As ComboBox, ByVal KeyCode As Integer) 'No comments it is clear . Dim Counter As Integer Dim Length As Integer If cboCtl.Text <> "" Then If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Then KeyCode = 0 Exit Sub End If For Counter = 0 To cboCtl.ListCount - 1 Length = Len(cboCtl.Text) If Mid(cboCtl.List(Counter), 1, Len(cboCtl)) = cboCtl.Text Then cboCtl.Text = cboCtl.List(Counter) cboCtl.SelStart = Length cboCtl.SelLength = Len(cboCtl.Text) cboCtl.ListIndex = Counter Exit For End If Next End If End Sub '=========================================== Typical usage : Private Sub cboCategory_Change() Call AutoCompleteList(cboCategory, mintKeyCode) End Sub Where mintKeyCode is a form variable given by a Form_KeyDown event like : Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) mintKeyCode = KeyCode End Sub and the cboCategory is the combo box filled by your own items. Taking into consideration the header of the form should look like this one : Option Explicit Private mintKeyCode As Integer and your form KeyPreview Property is set to TRUE. Enjoy ,
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.