AutoComplete v Combu

Postup:
Na formulß° p°idejte ComboBox. Pojmenujte jej cboAuto.
Do deklararΦnφ Φßsti formulß°e zapiÜte:

Option Explicit
Dim BackSpaced As Boolean

Na udßlost Load formulß°e zapφÜeme napln∞nφ Comba:

With cboAuto
   .AddItem "http://www.vbthunder.com"
   .AddItem "http://www.mvps.org/vb/"
   .AddItem "http://www.mvps.org/vbnet/"
   .AddItem "http://www.zonecorp.com"
   .AddItem "http://www.microsoft.com"
   .AddItem "http://www.mvps.org/ccrp/"
End With

Pro udßlosti na Combu:

Private Sub cboAuto_KeyDown(KeyCode As Integer, Shift As Integer)

   If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Then
      If cboAuto.Text <> "" Then
          'D∙le₧itΘ pro udßlost Change
          'jinak neodpovφ na mazßnφ znaku.
         BackSpaced = True
      End If
   End If

End Sub

Private Sub cboAuto_Change()

   'Pokud byla stisknuta klßvesa Backspace
   'nebo Delete, nelze spustit AutoComplete
   'Jinak se nebudete schopni vrßtit
    If BackSpaced = True Or cboAuto.Text = "" Then
      BackSpaced = False
      Exit Sub
   End If

   Dim i As Long
   Dim nSel As Long
   'Prob∞hneme skrz polo₧ky comba
   'a nalezneme prvnφ v²skyt °et∞zce.

   For i = 0 To cboAuto.ListCount - 1
      If InStr(1, cboAuto.List(i), cboAuto.Text, vbTextCompare) = 1 Then
         'ulo₧enφ SelStart
         nSel = cboAuto.SelStart
         cboAuto.Text = cboAuto.List(i)
          'Nastavenφ v²b∞ru v Combu
         cboAuto.SelStart = nSel
         cboAuto.SelLength = Len(cboAuto.Text) - nSel
         Exit For
      End If
   Next

End Sub

A te∩ aplikaci spus¥te. Zkuste psßt do comba.

Zp∞t

Autor: The Bozena