Click here to Skip to main content
       

C#

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionProblem with textbox key down and autocompletememberGrooverFromHolland24 Dec '12 - 10:34 
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

AnswerRe: Problem with textbox key down and autocompletememberGrooverFromHolland27 Dec '12 - 7:56 
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

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 18 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid