Autofill Combobox - Bug

lakkadghat

Member
Joined
Jul 26, 2003
Messages
12
Hello
The following code has been written to autofill combombox in my VB.NET Project.
It works absolutely fine in some machines while it doesnt work at all in some machines.
Does anyone have any idea.
The problem is that inthe the comboboxautofill function it executes the if string=0 part.
So it seems that in some machines it is not getting the string in the keypress event. but the event is being generated.

Please help me to solve my problems.

Private Sub Firstname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Firstname.KeyPress
fillcmb(Firstname, e)
End Sub

Private Sub fillcmb(ByRef cmbname As ComboBox, ByVal e As System.Windows.Forms.KeyPressEventArgs)
Try
Dim FindString As String
If Asc(e.KeyChar) = Keys.Escape Then
cmbname.SelectedIndex = -1
cmbname.Text = ""
ElseIf Asc(e.KeyChar) = Keys.Back Then
If cmbname.Text.Length > 0 Then
ComboBoxAutoComplete(cmbname, cmbname.Text.Remove(cmbname.Text.Length - 1, 1))
End If
Else
ComboBoxAutoComplete(cmbname, cmbname.Text)
End If
e.Handled = True
Catch ex As Exception
MsgBox(ex.Message & "Error Filling combobox", MsgBoxStyle.Critical)
End Try
End Sub

Private Sub ComboBoxAutoComplete(ByRef combo As ComboBox, ByVal str As String)
Try
Dim index As Integer
If str.Length = 0 Then
combo.SelectedIndex = -1
combo.Text = ""
combo.Text = combo.Text
Else
index = combo.FindString(str)
If index <> -1 Then
combo.SelectedIndex = index
combo.SelectionStart = str.Length
combo.SelectionLength = combo.Text.Length - combo.SelectionStart
End If
End If
Catch ex As Exception
MsgBox(ex.Message & "Error ComboAutocomplete Event", MsgBoxStyle.Critical)
End Try
End Sub
 
Back
Top