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

Strange combo box behavior

P: n/a
J L
I am trying to use the following code to auto fill a combo box
(credit and thanks to Code Project and Daryl)
Public Sub AutoFillCombo(ByVal theCombo As ComboBox, ByVal theKey As
Keys)
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String

Select Case theKey
Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
Return
End Select

With theCombo
sTypedText = .Text
iFoundIndex = .FindString(sTypedText)
If iFoundIndex >= 0 Then
oFoundItem = .Items(iFoundIndex)
sFoundText = .GetItemText(oFoundItem)
sAppendText = sFoundText.Substring(sTypedText.Length)
.Text = sTypedText & sAppendText
.SelectionStart = sTypedText.Length
.SelectionLength = sAppendText.Length
End If
End With
End Sub

The problem is this: If I have the name John in my combo box and type
in john (that is, using a small letter j not J), it automatically
fills the box with the John not john. I checked sTypedText just before
the .Text assignment and it is small letter j. So when .Text is set,
it seems to find the John entry and uses it..or something...what am I
missing here?

TIA,
John

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
J L
Opps, Just read further and see that the FindString search is not case
sensitive!

John

n Sun, 08 May 2005 07:45:57 -0700, J L <jo**@marymonte.com> wrote:
I am trying to use the following code to auto fill a combo box
(credit and thanks to Code Project and Daryl)
Public Sub AutoFillCombo(ByVal theCombo As ComboBox, ByVal theKey As
Keys)
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String

Select Case theKey
Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
Return
End Select

With theCombo
sTypedText = .Text
iFoundIndex = .FindString(sTypedText)
If iFoundIndex >= 0 Then
oFoundItem = .Items(iFoundIndex)
sFoundText = .GetItemText(oFoundItem)
sAppendText = sFoundText.Substring(sTypedText.Length)
.Text = sTypedText & sAppendText
.SelectionStart = sTypedText.Length
.SelectionLength = sAppendText.Length
End If
End With
End Sub

The problem is this: If I have the name John in my combo box and type
in john (that is, using a small letter j not J), it automatically
fills the box with the John not john. I checked sTypedText just before
the .Text assignment and it is small letter j. So when .Text is set,
it seems to find the John entry and uses it..or something...what am I
missing here?

TIA,
John


Nov 21 '05 #2

P: n/a
J L
Double opps...the case sensitive search still does not explain why the
..Text seems to convert the sTypedText to upper case...so mystery
continues...

John

On Sun, 08 May 2005 07:45:57 -0700, J L <jo**@marymonte.com> wrote:
I am trying to use the following code to auto fill a combo box
(credit and thanks to Code Project and Daryl)
Public Sub AutoFillCombo(ByVal theCombo As ComboBox, ByVal theKey As
Keys)
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String

Select Case theKey
Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
Return
End Select

With theCombo
sTypedText = .Text
iFoundIndex = .FindString(sTypedText)
If iFoundIndex >= 0 Then
oFoundItem = .Items(iFoundIndex)
sFoundText = .GetItemText(oFoundItem)
sAppendText = sFoundText.Substring(sTypedText.Length)
.Text = sTypedText & sAppendText
.SelectionStart = sTypedText.Length
.SelectionLength = sAppendText.Length
End If
End With
End Sub

The problem is this: If I have the name John in my combo box and type
in john (that is, using a small letter j not J), it automatically
fills the box with the John not john. I checked sTypedText just before
the .Text assignment and it is small letter j. So when .Text is set,
it seems to find the John entry and uses it..or something...what am I
missing here?

TIA,
John


Nov 21 '05 #3

P: n/a
Hi,

Here is a sample that works really well.
http://www.gotdotnet.com/Community/U...a-09bc8fd2860b

Ken
-------------------
"J L" <jo**@marymonte.com> wrote in message
news:t2********************************@4ax.com...
I am trying to use the following code to auto fill a combo box
(credit and thanks to Code Project and Daryl)
Public Sub AutoFillCombo(ByVal theCombo As ComboBox, ByVal theKey As
Keys)
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String

Select Case theKey
Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
Return
End Select

With theCombo
sTypedText = .Text
iFoundIndex = .FindString(sTypedText)
If iFoundIndex >= 0 Then
oFoundItem = .Items(iFoundIndex)
sFoundText = .GetItemText(oFoundItem)
sAppendText = sFoundText.Substring(sTypedText.Length)
.Text = sTypedText & sAppendText
.SelectionStart = sTypedText.Length
.SelectionLength = sAppendText.Length
End If
End With
End Sub

The problem is this: If I have the name John in my combo box and type
in john (that is, using a small letter j not J), it automatically
fills the box with the John not john. I checked sTypedText just before
the .Text assignment and it is small letter j. So when .Text is set,
it seems to find the John entry and uses it..or something...what am I
missing here?

TIA,
John
Nov 21 '05 #4

P: n/a
JL,

I was making a new sample for you yesterday, the one you use now has in my
idea needles to much sentences, I did not succeed directly and had to go,
however I see now that Ken supplied one. Your problem is probably that Jonh
is found in the items, and replaces that in the textbox (what it should do).

Cor
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.