Hi Eric
This is a useful sub that I have also been looking for. Thanks!
Just in case some completely newbies look in this code I have corrected two
things:
You need to declare a controlKey boolean variable in the top of your form
code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Controlkey As Boolean
' And I believe one of your If-Endif was misplaced
Private Sub cboProduct_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles cboProduct.KeyPress
Dim Combo As ComboBox = CType(sender, ComboBox)
If Asc(e.KeyChar) = Keys.Escape Then
Combo.SelectedIndex = -1
Combo.Text = ""
Controlkey = True
ElseIf Char.IsControl(e.KeyChar) Then
Controlkey = True
Else
Controlkey = False
End If
End Sub
Private Sub cboProduct_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboProduct.TextChanged
Dim Combo As ComboBox = CType(sender, ComboBox)
If Combo.Text <> "" And Not Controlkey Then
Dim MatchText As String = Combo.Text
Dim Match As Integer = Combo.FindString(MatchText, -1)
If Match <> -1 Then
Combo.SelectedIndex = Match
Combo.SelectionStart = MatchText.Length
Combo.SelectionLength = Combo.Text.Length - Combo.SelectionStart
End If
End If
End Sub
Private Sub cboProduct_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboProduct.Leave
Dim Combo As ComboBox = CType(sender, ComboBox)
If Combo.Text <> "" Then
Dim MatchText As String = Combo.Text
Dim Match As Integer = Combo.FindStringExact(MatchText)
If Match <> -1 Then
Combo.SelectedIndex = Match
Else
Label1.Text = "Not in list"
Combo.Focus()
Combo.SelectAll()
End If
End If
End Sub
This code works in my projects anyway.
Best regards
Jan
"EricJ" <ericRéMo**@ThiSomnipack.be> skrev i en meddelelse
news:3f*********************@reader3.news.skynet.b e...
this dous w you need (deleted some things but normally nothing essential)
Private Sub cboProduct_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles cboProduct.KeyPress
Dim Combo As ComboBox = CType(sender, ComboBox)
If Asc(e.KeyChar) = Keys.Escape Then
Combo.SelectedIndex = -1
Combo.Text = ""
Controlkey = True
ElseIf Char.IsControl(e.KeyChar) Then
Controlkey = True
Else
Controlkey = False
End If
End Sub
Private Sub cboProduct_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboProduct.TextChanged
Dim Combo As ComboBox = CType(sender, ComboBox)
If Combo.Text <> "" And Not Controlkey Then
Dim MatchText As String = Combo.Text
Dim Match As Integer = Combo.FindString(MatchText, -1)
'als gevonden invoegen
If Match <> -1 Then
Combo.SelectedIndex = Match
'de toegevoegde tekst selecteren zodat de gebruiker verder kan typen
Combo.SelectionStart = MatchText.Length
Combo.SelectionLength = Combo.Text.Length - Combo.SelectionStart
End If
End Sub
Private Sub cboProduct_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboProduct.Leave
Dim Combo As ComboBox = CType(sender, ComboBox)
If Combo.Text <> "" Then
'zoeken naar zelfde
Dim MatchText As String = Combo.Text
Dim Match As Integer = Combo.FindStringExact(MatchText)
If Match <> -1 Then
Combo.SelectedIndex = Match
End If
Else
stbp2.Text = "Not in list"
Combo.Focus()
Combo.SelectAll()
End If
End If
End Sub
"Mr. B" <Us**@NoWhere.Com> wrote in message
news:7v********************************@4ax.com... Here's the situation...
You've a combobox with Items already added. Say they look like this (or
even lines of text):
10-00-232
10-00-256
10-01-006
10-01-213
10-02-200
10-03-045
How does one code the Combobox so that when you manually start to enter
the Item in the Combobox line, it AutoCompletes the input??
Many thanks!
Bruce