works fine on the developer's computers

T

ToddT

the following code snippet implements an "auto complete" functionality
for combo boxes. it works fine on all the developer's computers but
only selects the first item in the combo box on non-developer's
computers. what kind of workstation configuration difference could
cause this kind of problem? i'm at a lost...


Private Sub cboCountry_KeyPress(ByVal sender As System.Object, ByVal
keyPressArgs As System.Windows.Forms.KeyPressEventArgs) Handles
cboCountry.KeyPress

Dim keyCode As Integer
Dim index As Integer
Dim searchString As String

keyCode = Convert.ToInt32(keyPressArgs.KeyChar)

Select Case(keyCode)
Case Keys.PageDown
<snip>

' Scroll the scrollable panel up
Case Keys.PageUp
<snip>

Case Keys.Down, Keys.Up, Keys.Back, Keys.Right, Keys.Left
<snip>

Case Else
searchString = cboCountry.Text
index = cboCountry.FindString(searchString)

If (index >= 0) Then
cboCountry.SelectedIndex = index
cboCountry.SelectionStart = searchString.Length
cboCountry.SelectionLength =
cboCountry.Text.Length - cbo.SelectionStart

previousIndex = index
Else
cboCountry.SelectedIndex = previousIndex
cboCountry.SelectionStart =
searchString.Length - 1
cboCountry.SelectionLength =
cboCountry.Text.Length - cboCountry.SelectionStart
End If

keyPressArgs.Handled = True
End Select
End Sub ' cbo_KeyPress()
 
J

Jan Hyde

ToddT <[email protected]>'s wild thoughts were
released on Wed, 13 Oct 2004 08:05:33 -0500 bearing the
following fruit:
the following code snippet implements an "auto complete" functionality
for combo boxes. it works fine on all the developer's computers but
only selects the first item in the combo box on non-developer's
computers. what kind of workstation configuration difference could
cause this kind of problem? i'm at a lost...

It doesn't work here. When the keypress event fires the
combo test is empty, therefore it selects the first item in
the list because previous index = 0. If I move the code to
the keyup event the correct entry is selected.

J
Private Sub cboCountry_KeyPress(ByVal sender As System.Object, ByVal
keyPressArgs As System.Windows.Forms.KeyPressEventArgs) Handles
cboCountry.KeyPress

Dim keyCode As Integer
Dim index As Integer
Dim searchString As String

keyCode = Convert.ToInt32(keyPressArgs.KeyChar)

Select Case(keyCode)
Case Keys.PageDown
<snip>

' Scroll the scrollable panel up
Case Keys.PageUp
<snip>

Case Keys.Down, Keys.Up, Keys.Back, Keys.Right, Keys.Left
<snip>

Case Else
searchString = cboCountry.Text
index = cboCountry.FindString(searchString)

If (index >= 0) Then
cboCountry.SelectedIndex = index
cboCountry.SelectionStart = searchString.Length
cboCountry.SelectionLength =
cboCountry.Text.Length - cbo.SelectionStart

previousIndex = index
Else
cboCountry.SelectedIndex = previousIndex
cboCountry.SelectionStart =
searchString.Length - 1
cboCountry.SelectionLength =
cboCountry.Text.Length - cboCountry.SelectionStart
End If

keyPressArgs.Handled = True
End Select
End Sub ' cbo_KeyPress()


Jan Hyde (VB MVP)
 
T

ToddT

it doesn't make sense that it works fine as coded for all the
developers here. i will try moving the code to the key up event
handler and see if that works. thx jan.
 
T

ToddT

after moving the code to the key up event handler, it now works for
everyone. i wonder why...

thx for the suggestion jan.
 
Top