i write one program that have mant textbox for entry data into database but i want when user enter data in textbox and press 'Enter' ,change focus to another textbox.

can anyone have idea for hep me?
thanks.

Recommended Answers

All 9 Replies

Member Avatar for iamthwee

This is well documented on the net. What have you searched for?

Look at
http://msdn2.microsoft.com/en-us/library/system.windows.forms.keypresseventargs.keychar.aspx
then after e.Handled = true; set focus to the next control / textbox.

thanks for your replay,
but when i press enter corsur hide and don't set next focus.
if (e.KeyChar == (char)13)//press Enter Key
{
Control currCtl = (Control)sender; //current control
e.Handled = true;
Control c = GetNextControl(currCtl, true);
c.Focus();
}

please send the error of this code.

thank you very much..

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
Control c = GetNextControl((Control)sender, true);
if (c != null)
c.Focus();
}

This works fine.

in the key down event of text box write this code
if e.KeyCode=Keys.Enter then
send.keys("tab")
end if

Hi,
I Have This problem too, but in asp.net
How can i do this action in asp.net(C#)??
Thanks

ASP.net don't have keypress event for textbox

Firstly, please try not to resurrect old threads as this violates daniweb forum rules.
Secondly, this is the C# board, if your problem is ASP.net related then you will have access to a better pool of knowledge and experience if you post it on the asp.net board.
Lastly, if you want to move focus between texboxes you probably dont want to submit the form after each textbox is completed so putting code in your C# code behind isn't going to help you. Anything you want to run at the server goes in your code behind and is processed by submitting the page to the server; if you want to perform an action between posts then you will need to use a client side scripting langauge like JavaScript. There is an example of Javascript key press event here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.