Vous avez une ComboBox remplit de données issues de votre base de données et vous voulez completer la saisie au lieu de dérouler la ComboBox pour chercher votre donnée.
Voilà le code VB ...
Source / Exemple :
' M O D U L E
'--------------------------------------------------------------------------------
' www.idev.fr.st
'
' Syntax
' ------
' In the CHANGE event of your ComboBox, put in the following line
' iSenseChange YourComboBoxName
' Where "YourComboBoxName" is the name of the ComboBox associated with the event.
'
' In the KEYPRESS event of your ComboBox, put in the following line
' iSenseKeyPress YourComboBoxName, KeyAscii
' Where "YourComboBoxName" is the name of the ComboBox associated with the event.'
'
' ADAPTED FROM :
'--------------------------------------------------------------------------------
' IntelliSense for VB the TextBox Control.
' Danny Young
' dan@mydan.com
' http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9313&lngWId=1
'--------------------------------------------------------------------------------
Option Explicit
Global WasDelete As Boolean
Public Function IntelliSense(cBox As ComboBox, AddRecord As Boolean) As String
Dim i As Integer
Dim Done As Boolean
If AddRecord Then
'Pour ajouter le texte dans la ComboBox
'cBox.AddItem cBox.Text
Else
' For i = 0 To cBox.ListCount And Done = False
For i = cBox.ListCount To 0 Step -1 And Done = False
If UCase(cBox.Text) = Mid(RTrim(UCase(cBox.List(i))), 1, Len(cBox.Text)) Then
IntelliSense = RTrim(cBox.List(i))
End If
Next i
End If
End Function
Public Sub iSenseChange(cBox As ComboBox)
Dim iStart As Integer
Dim iSense As String
iStart = cBox.SelStart
iSense = IntelliSense(cBox, False)
If iSense <> "" And Not WasDelete Then
cBox.Text = iSense
cBox.SelStart = iStart
cBox.SelLength = Len(cBox.Text) - iStart
End If
End Sub
Public Sub iSenseKeyPress(cBox As ComboBox, KeyAscii As Integer)
If KeyAscii = 13 And cBox.Text <> "" Then
IntelliSense cBox, True
ElseIf KeyAscii = 8 Then
WasDelete = True
Else
WasDelete = False
End If
End Sub
Conclusion :
Après avoir longtemps cherché ce type de source, j'ai enfin trouvé.
Une adaptation a été faite pour associer ce code à une ComboBox.
Le source original était associé à une TextBox lisant les données dans un fichier.
Merci à Danny Young pour son source posé sur
http://www.planet-source-code.com
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.