Click here to Skip to main content
16,016,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There have three TextBox.

After typing the text at 3rd TextBox, want to go back and select to 2nd TextBox whithout deleting the 3rd TextBox's Data,
by using the Backspace key,
Actually, I write the cursor to jump to the first position of first charachter of 3rd TextBox and then jump to 2nd TextBox.
But always deleting the last character of 3rd TextBox.

C#
private void TextBox3_KeyDown(object sender, KeyEventArgs e)
      {
          if (e.KeyValue == 8)
          {
              e.Handled = true;             
              TextBox3.SelectionStart = TextBox3.Text.Length;
              TextBox2.Select();
          }


how should i do for that?

thanks
ttds
Posted
Updated 7-Mar-13 0:55am
v2
Comments
johannesnestler 7-Mar-13 5:14am    
I'm just curious... Why don't use Tab (Shift+Tab) to go back in a "normal" way? I think this backspace behaviour would confuse me from a users perspective. If I misstype something (happens quite often) and use backspace to delete it - the focus would jumpt to the former textbox?

I agree with the comment that altering a standard behaviour may confuse users. However to consume a keystroke you should set the SuppressKeyPress property in the KeyDown event handler, e.g.
C#
private void TextBox_KeyDown(object sender, KeyEventArgs e) {
  if (e.KeyCode == System.Windows.Forms.Keys.Back) {
    e.SuppressKeyPress = true;
    // no need to set e.Handled
    otherTextBox.Select();
  }
}

Thats how it's done, but I do think you would be better off setting a sequential tab order for the TextBoxes and navigating between them using the Tab and Shift-Tab keys.

Alan
 
Share this answer
 
If three textboxes are layed out in such a way that one tabs to the other i.e. the tab indexes are one after the other, you can use SendKeys.Send[^] to send a combination of "shift + tab" to tab to previous text box.
 
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