Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All

i have windows App
some text boxs
i tab between textbox by this code

private void AstTxt_KeyDown(object sender, KeyEventArgs e)
  {
     if (e.KeyCode == Keys.Enter)
      {
         AltTxt.Focus();

       } 
   }



but i want when go next text box
select data in this textbox not delete it
Posted
Comments
Sergey Alexandrovich Kryukov 17-Mar-15 16:37pm    
TextBox? Which one? Full type name, please.
—SA

Hello,
try the following:
private void AstTxt_KeyDown(object sender, KeyEventArgs e)
  {
     if (e.KeyCode == Keys.Enter)
      {
         AltTxt.Focus();

         AltTxt.SelectionStart = 0;
         AltTxt.SelectionLength = AltText.Text.Length;

       } 
   }
 
Share this answer
 
v2
Comments
ramadan2 17-Mar-15 16:20pm    
thanx dear
macika123 17-Mar-15 16:24pm    
You're welcome ;-)!
TextBox, under Focus[^] event doesn't delete the text inside it. It just changes the focus from other controls, to this one.

Secondly, to select entire text inside the TextBox, you can use the Selection (SelectionStart[^] and SelectionLength[^]) properties, to enter the characters that you want to select in the current selection; read more on MSDN links. Since you want to select all of them, try this,

C#
// Set the focus
AltText.Focus();

// Since beginning; zeroth character
AltTxt.SelectionStart = 0;
// Upto the last character.
AtlTxt.SelectionLength = textbox.Text.Length;


Above code would select the text from the control when you're inside it. There is no code to delete it, so it won't delete anything from the TextBox.
 
Share this answer
 
v2
Comments
ramadan2 17-Mar-15 16:19pm    
thanx dear

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