![]() |
Tipp 0224
|
Auto-Vervollständigung in einer ComboBox
|
 |
|
Autor/Einsender: Datum: |
|
Michael Werner 15.04.2002 |
|
Entwicklungsumgebung: |
|
VB 5 |
|
|
Dieser Tipp zeigt, wie man mit ein paar Zeilen Code im KeyUp-Ereignis einer
ComboBox eine Auto-Vervollständigung erreichen kann, ähnlich wie es im
Internet-Explorer bei der Eingabe einer Internet-Adresse möglich ist.
|
|
|
Option Explicit
Private Sub Form_Load()
With Combo1
.AddItem "Adalbert"
.AddItem "Alex"
.AddItem "Angie"
.AddItem "Anton"
.AddItem "Berta"
.AddItem "Detlev"
.AddItem "Dieter"
.AddItem "Egon"
.AddItem "Eugen"
.AddItem "Fred"
.AddItem "Freddi"
.AddItem "Martin"
.AddItem "Michael"
.AddItem "Richard"
.AddItem "Sebastian"
.AddItem "Vb-Fun"
.AddItem "VbArchiv"
.Text = ""
End With
Label1.Caption = "Tippen Sie z.B. ein ""v"" in die Combobox:" & _
vbCrLf & "und dann z.B. ""ba"""
End Sub
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Static NoSelectText As String
Dim i As Long
With Combo1
If KeyCode = vbKeyUp Then Exit Sub
If KeyCode = vbKeyDown Then Exit Sub
If KeyCode = vbKeyLeft Then Exit Sub
If KeyCode = vbKeyRight Then Exit Sub
If KeyCode <> vbKeyBack Then
NoSelectText = Mid(.Text, 1, Len(.Text) - .SelLength)
Else
If NoSelectText <> "" Then
NoSelectText = Mid(NoSelectText, 1, Len(NoSelectText) - 1)
End If
End If
For i = 0 To .ListCount - 1
If UCase(NoSelectText) = _
UCase(Mid(.List(i), 1, Len(NoSelectText))) Then
.ListIndex = i
Exit For
End If
Next
.SelStart = Len(NoSelectText)
.SelLength = Len(.Text)
If .ListIndex = -1 Then
.Text = ""
.BackColor = vbWhite
Else
.BackColor = vbWindowBackground
End If
End With
End Sub
|
|
|
|
|
Windows-Version |
95 |
 |
|
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
VB-Version |
VBA 5 |
 |
|
VBA 6 |
 |
|
VB 4/16 |
 |
|
VB 4/32 |
 |
|
VB 5 |
 |
|
VB 6 |
 |
|
|
|
Download (2,6 kB)
|
Downloads bisher: [ 2396 ]
|
|
|