salve a tutti!
ho l'esigenza di fare una combobox autocomplete.. ora per l'autocomplete nn c'è problema (+/-), guardando la documentazione di vb ho trovato come i signori microsoft affrontano l'autocomplete.. nn fosse che se uno scrive velocemente l'autocomplete da dei problemi.. scrive la prima parola che trova.. se qualcuno ha qualche consiglio su come risolvere il problema.. vi posto il codice:
codice:
Private Sub cmbTitoli_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbTitoli.KeyUp
Dim index As Integer
Dim actual As String
Dim found As String
' Do nothing for some keys such as navigation keys.
If ((e.KeyCode = Keys.Back) Or _
(e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Delete) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.End)) Then
Return
End If
' Store the actual text that has been typed.
actual = Me.cmbTitoli.Text
' Find the first match for the typed value.
index = Me.cmbTitoli.FindString(actual)
' Get the text of the first match.
If (index > -1) Then
found = Me.cmbTitoli.Items(index).ToString()
' Select this item from the list.
Me.cmbTitoli.SelectedIndex = index
' Select the portion of the text that was automatically
' added so that additional typing will replace it.
Me.cmbTitoli.SelectionStart = actual.Length
Me.cmbTitoli.SelectionLength = found.Length
End If
End Sub
Per funzionare correttamente una persona deve scrivere pianissimo!
l'altro problema è che vorrei che la finestra di scorrimento della combobox si aprisse mentre uno sta scrivendo.. questo problema l'avevo risolto in vb6 inviando un messaggio CB_SHOWDROPDOWN alla combobox con l'api send message..
ora però in .net nn so come fare!
Grazie mille!