Up/Down keys do not work with AutoComplete SuggestAppend textbox

johnpapa

Member
Joined
Aug 10, 2013
Messages
23
Programming Experience
10+
I have a textbox in a DataGridView and I use the following code to AutoComplete, SuggestAppend. It appears to work OK apart from the fact that when the dropdown list appears, I cannot use the Up/Down keys to scroll through the list and I have to use the mouse to make a selection. If I click the Up/Down keys or if I lick anywhere on the screen outside the textbox and dropdown list the first item of the list is selected.

Please help. It is driving me crazy.

John

VB.NET:
Private Sub dgvAppointment_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles dgvAppointment.EditingControlShowing


        If (dgvAppointment.CurrentCell.ColumnIndex = DFN_GRID_intPatientID_COL) Then
            ItemCode = TryCast(e.Control, TextBox)
            ItemCode.Name = "textbox1"
            AddHandler ItemCode.TextChanged, AddressOf ItemCode_Changed
            AddHandler ItemCode.PreviewKeyDown, AddressOf ItemCode_PreviewKeyDown
            namesCollection.Add("")
            If ItemCode IsNot Nothing Then
                If dgvAppointment.CurrentCell.ColumnIndex = DFN_GRID_intPatientID_COL Then
                    With DirectCast(e.Control, TextBox)
                        .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                        .AutoCompleteSource = AutoCompleteSource.CustomSource
                        .AutoCompleteCustomSource = namesCollection
                    End With
                Else
                    With DirectCast(e.Control, TextBox)
                        .AutoCompleteMode = AutoCompleteMode.None
                    End With
                End If
            End If
        End If
    End Sub

    Private Sub ItemCode_Changed(sender As Object, e As EventArgs)

        Me.txtCounter.Text = CStr(CInt(Me.txtCounter.Text) + 1)

        Dim textbox As TextBox = TryCast(sender, TextBox)
        Try
            If textbox.TextLength = 0 Then
                intmTextLength = -1
            End If

            If (intmTextLength = -1) Or (System.Math.Abs(textbox.TextLength - intmTextLength) = 1) Then
                intmTextLength = textbox.TextLength
                GetPatientByLastFirstTel(textbox.Text)
            Else

            End If

        Catch ex As Exception

        End Try
    End Sub
 
Back
Top