Click here to Skip to main content
16,016,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to All.

I hav a form having about 20 textboxes.I want to navigate each text box using enter button,but without writting code for each textbox's keypress event.Plz give me an alternate method,so that i dont hav to write code on each control's keypress event.Also plz post the code if possible.

This site has solved my many problems.Hoping for a solution of my next problem.
Thanx
Posted

what do you mean you want to "navigate" them?

If you want to check their values, you could simply iterate through them in the button click event handler.
 
Share this answer
 
Have you tried something like:
C#
if (e.KeyChar == ‘\r’)
{
e.Handled = true;
System.Windows.Forms.SendKeys.Send("{TAB}");
}

Override the form’s OnKeyUp or override ProcessKeyTab...

Btw, you say:
Deepak.xip wrote:
This site has solved my many problems.

Looked at the questions you had asked till now. Found only one marked as answer accepted!
 
Share this answer
 
I love it when people throw answer out there without actually testing if it will work.

I assume that you're saying that you want the user to be typing in a textbox and when they hit enter, it takes them to the next textbox, correct?

Overriding the form's OnKeyUp will not work because if you are in a textbox, the form's OnKeyUp won't fire because it doesn't have the focus.

But, first, make sure that your textboxes all have the correct TabIndex set for the order you want. Then, just write a single process for a textbox KeyUp event and check the KeyData for Keys.Enter. If it is the enter key, then you can do the System.Windows.Form.SendKeys.Send("{TAB}"). Then, just add that process handler to each of the textboxes that you want it to handle.
 
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