Problem with textbox key down and autocomplete
-
Hi all, I have a textbox with autocomplete set to suggest. I want to execute my code in the Textbox_KeyDown event on the enter key, but enter key is also invoked when I select an item from the text box autocomplete items. That is not what I want. I want the selected item in the textbox and then execute my code. code:
private void opdrverwTextbox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == (Keys.Enter) && !string.IsNullOrEmpty(opdrverwTextbox.Text))
{
//here is the problem. In debugging if I select from dropdown
// with mouse click: e.KeyData = LButton | MButton | Back
e.Handled = true;
a lot of other code........;} opdrverwTextbox.Clear(); opdrverwTextbox.Visible = false; opdrverwLabel.Visible = false; dataGridView\_Update(); } }
I don't want to set autocomplete to suggest-append. is there a workaround for this?
Merry Christmas,
Groover b>
0200 A9 23 0202 8D 01 80 0205 00
-
Hi all, I have a textbox with autocomplete set to suggest. I want to execute my code in the Textbox_KeyDown event on the enter key, but enter key is also invoked when I select an item from the text box autocomplete items. That is not what I want. I want the selected item in the textbox and then execute my code. code:
private void opdrverwTextbox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == (Keys.Enter) && !string.IsNullOrEmpty(opdrverwTextbox.Text))
{
//here is the problem. In debugging if I select from dropdown
// with mouse click: e.KeyData = LButton | MButton | Back
e.Handled = true;
a lot of other code........;} opdrverwTextbox.Clear(); opdrverwTextbox.Visible = false; opdrverwLabel.Visible = false; dataGridView\_Update(); } }
I don't want to set autocomplete to suggest-append. is there a workaround for this?
Merry Christmas,
Groover b>
0200 A9 23 0202 8D 01 80 0205 00
Hi all, Found a solution myself after long google search. It works but can someone explain how? here is my new code:
**\[System.Runtime.InteropServices.DllImport("user32.dll")\] private static extern short GetKeyState(Keys key);** private void opdrverwTextbox\_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == (Keys.Enter) && !string.IsNullOrEmpty(opdrverwTextbox.Text)**&& GetKeyState(Keys.Enter) < 0)** { e.Handled = true; a lot of other code........; } opdrverwTextbox.Clear(); opdrverwTextbox.Visible = false; opdrverwLabel.Visible = false; dataGridView\_Update(); }
Groover,
0200 A9 23 0202 8D 01 80 0205 00