Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have to append any alphanumeric keys pressed on form in textbox control in windows application.

I have written code in _Keydown event for form for this, as below
C#
private void DataSummary_KeyDown(object sender, KeyEventArgs e)
{
    txtSearch.Text = txtSearch.Text + e.KeyCode;     
}


If I press any alphanumeric key , txtSearch always contain 2 instances of number.

Actually _KeyDown event in C# get called twice in windows application

Please share your knowledge..

Thanks in advance.

Regards,
Nagraj N
Posted
Updated 25-Sep-11 19:11pm
v2
Comments
Pravin Patil, Mumbai 26-Sep-11 1:13am    
Have you written any TextChanged or Keyup event as well...? Because code seems correct and there is no reason that Keydown event will get fired twice if you are calling it explicitly....

1 solution

There is no such even as _Keydown. Your DataSummary_KeyDown is just a name of a method, you provide no proof that it is used in the invocation list of the event KeyDown of any control. You also have no proof that it is called twice. Strictly speaking, even is not exactly called, it has a special mechanism for invocation of handlers. You could code millions of clever or stupid things to call the handler twice or just give yourself an impression of such effect. Without looking at your code nothing else can be said.

You could use "Improve question" above and provide correct problem report. However, don't do it just yet.

Simply put a breakpoint at your handler method and see under debugger where it is called from. Use "call stack" debugger window. You will immediately see what's going on. And break the habit of asking any questions before you use debugger.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900