By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,275 Members | 1,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,275 IT Pros & Developers. It's quick & easy.

AutoComplete Entry in ComboBox?

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
http://www.csharphelp.com/archives3/archive502.html
http://www-level3.experts-exchange.c..._20677158.html

HTH,

Bill
"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

Jul 21 '05 #2

P: n/a
With Deft Fingers, "William Ryan" <do********@nospam.comcast.net> wrote:
http://www.csharphelp.com/archives3/archive502.html
http://www-level3.experts-exchange.c..._20677158.html


Awwwww... William... you C# guy... sadly to say I'm only a VB.net kinda person
(:

But Thanks any ways...

Bruce
Jul 21 '05 #3

P: n/a
Hi Bruce,
that shouldn't too much of a problem. First of all it's not very hard to
port C# to VB.net. At least if you have a basic understanding of the C/C#
syntax.
On the other just download the zip from C# help (1st link William provided).
If haven't verified but it states the compiled dll is there, too. This
should be useable without problems from any .NET language.

Matti

"Mr. B" <Us**@NoWhere.Com> schrieb im Newsbeitrag
news:i4********************************@4ax.com...
With Deft Fingers, "William Ryan" <do********@nospam.comcast.net> wrote:
http://www.csharphelp.com/archives3/archive502.html
http://www-level3.experts-exchange.c...g_Languages/C_

Sharp/Q_20677158.html
Awwwww... William... you C# guy... sadly to say I'm only a VB.net kinda person (:

But Thanks any ways...

Bruce

Jul 21 '05 #4

P: n/a
With Deft Fingers, "Matthias Klöpper" <mk*******@ba-com.net> wrote:
that shouldn't too much of a problem. First of all it's not very hard to
port C# to VB.net. At least if you have a basic understanding of the C/C#
Okay... don't know anything about C# though (:
If haven't verified but it states the compiled dll is there, too. This
should be useable without problems from any .NET language.


A DLL file? Hmmm... I'll see about that.

Thanks!

Bruce
Jul 21 '05 #5

P: n/a
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

Jul 21 '05 #6

P: n/a
i'll do you 1 better... here is a link to a c# -- VB converter.
I grabbed this from someone on this news forum (I forget from whom exactly)

http://kryptonite.headsense.com/CSToVBWeb/

maybe kryptonite...
"Mr. B" <Us**@NoWhere.Com> wrote in message
news:8e********************************@4ax.com...
With Deft Fingers, "Matthias Klöpper" <mk*******@ba-com.net> wrote:
that shouldn't too much of a problem. First of all it's not very hard to
port C# to VB.net. At least if you have a basic understanding of the C/C#


Okay... don't know anything about C# though (:
If haven't verified but it states the compiled dll is there, too. This
should be useable without problems from any .NET language.


A DLL file? Hmmm... I'll see about that.

Thanks!

Bruce

Jul 21 '05 #7

P: n/a
With Deft Fingers, ":\\\\derian" <de****@someplace.com> wrote:
i'll do you 1 better... here is a link to a c# -- VB converter.
I grabbed this from someone on this news forum (I forget from whom exactly)


Interesting... I'll check it out.

Thanks!

Bruce
Jul 21 '05 #8

P: n/a
With Deft Fingers, "EricJ" <ericRéMo**@ThiSomnipack.be> wrote:
this dous w you need (deleted some things but normally nothing essential)


Thanks. I'll try to see if I can get it to work.

Regards,

Bruce
Jul 21 '05 #9

P: n/a
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


Jul 21 '05 #10

P: n/a
correct i forgot the Private Controlkey as boolean and i deleted an end if
to much :)

btw if you are interested in only auto filling when there is only 1 inctance
of the text you are typing i have that 2 (boss dousn't like the possibility
of fast inputters making mistakes)

"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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

Jul 21 '05 #11

P: n/a
Hi Eric
Actually I have a little problem with your code.
I have a sub on the SelectedIndexChanged for my combo that creates an email.
And your code calls this.

So if I have ie IPC and IPA in the combo item list, when I type I-P it
selects the first (IPA or IPC depending on my sort order) and trigger my
SelectedIndexChanged sub and creates an email for the first item matching
I-P. It does not give me a chance to decide whether I actually wanted
another item starting with IP.

Jan

"EricJ" <ericRéMo**@ThiSomnipack.be> skrev i en meddelelse
news:3f**********************@reader2.news.skynet. be...
correct i forgot the Private Controlkey as boolean and i deleted an end if
to much :)

btw if you are interested in only auto filling when there is only 1 inctance of the text you are typing i have that 2 (boss dousn't like the possibility of fast inputters making mistakes)

"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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


Jul 21 '05 #12

P: n/a

that is becouse you change the selected index when the text changes, have a
look at the following
here it wil not select anithing until there is only 1 possibility left if
there are more possiblilities it wil convert the text to uppercase so the
user knows he's not typing anithing wrong

i didn't test this against the selected index changed but i think you can
work with this

i did wonder wouldn't it be better to generate your e-mail in the leave
event? you can check if the value has changed there.
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

'zoeken naar zelfde

Dim MatchText As String = Combo.Text

Dim Match As Integer = Combo.FindString(MatchText, -1)

'als gevonden invoegen

If Match <> -1 Then

Dim y As Integer = 1

Dim g As Integer

g = Combo.FindString(MatchText, Match + 1)

If g <> Match Then

y += 1

End If

If y = 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

Else

Combo.Text = MatchText.ToUpper

Combo.SelectionStart = MatchText.Length

'Combo.SelectionLength = Combo.Text.Length - Combo.SelectionStart

End If

End If

End If

End Sub

"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Eric
Actually I have a little problem with your code.
I have a sub on the SelectedIndexChanged for my combo that creates an email. And your code calls this.

So if I have ie IPC and IPA in the combo item list, when I type I-P it
selects the first (IPA or IPC depending on my sort order) and trigger my
SelectedIndexChanged sub and creates an email for the first item matching
I-P. It does not give me a chance to decide whether I actually wanted
another item starting with IP.

Jan

Jul 21 '05 #13

P: n/a
Hi Eric
Thanks for answering
I also send an email in the Leave event.
But I would _also_ like the user to be able to select a group from the list
and see the email generated without having to press Enter or move focus from
the combo.

I shall look into your example

Thanks

Jan

"EricJ" <ericRéMo**@ThiSomnipack.be> skrev i en meddelelse
news:3f**********************@reader2.news.skynet. be...

that is becouse you change the selected index when the text changes, have a look at the following
here it wil not select anithing until there is only 1 possibility left if
there are more possiblilities it wil convert the text to uppercase so the
user knows he's not typing anithing wrong

i didn't test this against the selected index changed but i think you can
work with this

i did wonder wouldn't it be better to generate your e-mail in the leave
event? you can check if the value has changed there.
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

'zoeken naar zelfde

Dim MatchText As String = Combo.Text

Dim Match As Integer = Combo.FindString(MatchText, -1)

'als gevonden invoegen

If Match <> -1 Then

Dim y As Integer = 1

Dim g As Integer

g = Combo.FindString(MatchText, Match + 1)

If g <> Match Then

y += 1

End If

If y = 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

Else

Combo.Text = MatchText.ToUpper

Combo.SelectionStart = MatchText.Length

'Combo.SelectionLength = Combo.Text.Length - Combo.SelectionStart

End If

End If

End If

End Sub

"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Eric
Actually I have a little problem with your code.
I have a sub on the SelectedIndexChanged for my combo that creates an

email.
And your code calls this.

So if I have ie IPC and IPA in the combo item list, when I type I-P it
selects the first (IPA or IPC depending on my sort order) and trigger my
SelectedIndexChanged sub and creates an email for the first item matching I-P. It does not give me a chance to decide whether I actually wanted
another item starting with IP.

Jan


Jul 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.