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.

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.

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.

This article has been dead for over six months. Start a new discussion instead.