I'm using the DropdownStyle Combobox: Dropdown
If I press on the keyboard with enter then only once but why if I press on the keyboard with escape then it must be done twice,
I use the String.Equals Method to check the value selected in the combox is correct or not by referring to the textbox.
why do I have to press escape on the keyboard twice?
or is there another method that I have to do
Is there something wrong with my code?
Please guide me
Thanks
Public Class Form4
Private count As Integer = 1
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData.ToString() = "Escape" Then
If count = 1 Then
count += 1
Label1.Text = "You are pressing key escape once"
ElseIf count = 2 Then
Label1.Text = "You are pressing key escape twice"
End If
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
ComboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
ComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
End Sub
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.AutoCompleteCustomSource = AutoSuggestList()
End Sub
Private Function AutoSuggestList() As AutoCompleteStringCollection
Dim collection As New AutoCompleteStringCollection
Using connection As New OleDbConnection(GetOledbConnectionString())
collection.AddRange(connection.Query(Of String)("SELECT ColorCode FROM ColorCode").ToArray)
End Using
Return collection
End Function
Private Sub GetItemData(ByVal iditem As String)
Dim item = COLORCODESERVICE.GetByColorcode2(iditem)
If item IsNot Nothing Then
If String.Equals(iditem, item.Colorcode, StringComparison.CurrentCultureIgnoreCase) Then
ComboBox1.Text = item.Colorcode
End If
TextBox1.Text = item.Colorname
Else
MsgBox("Not Found Colorcode...")
ComboBox1.ResetText()
TextBox1.Clear()
Return
End If
End Sub
Private Sub ComboBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles ComboBox1.KeyDown
If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Escape Then
GetItemData(ComboBox1.Text)
ElseIf e.KeyCode = Keys.Back Then
ComboBox1.ResetText()
TextBox1.Clear()
End If
End Sub
End Class

Typically you use a ComboBox as way to select a valid value.
Compare this to what you have,