locked
Selecting entire text when text box gets focus (kaysiehaas) - 5/30/2007 12:48 PM PST RRS feed

  • Question

  • By: kaysiehaas

    I am trying to find out how to format my text box on a form in a way that 
    when the textbox gets focus it selects all the text in that box.  
    Tuesday, February 19, 2008 11:35 PM

Answers

  • Hi Kaysiehass,

    I think Kesavan_K has misunderstood your question.

    This is relatively simple solution.  Add a event handler for 'GotFocus' Event in XAML file as shown below,

    <TextBox HorizontalAlignment="Left" Margin="37,130,0,175" Width="259" Text="TextBox" TextWrapping="Wrap" GotFocus="GotFocused" x:Name="nameTextBox"/>

    And now in the code behind file add the following code.

    private void GotFocused(object sender, RoutedEventArgs e)
    {
    nameTextBox.SelectAll();
    }


    Hope this answers your question.

    -BALA.

    Saturday, August 30, 2008 12:44 PM

All replies

  • Hi,

         The best solution for ur problem is binding element property.


         In expression blend it is pretty simple.

         1.right click the visibility of the controls u want to change, go to Data Binding.
         2.Click "Element Property"(in center)
         3.Select ur  Textboxes from left column and select the Select(as per ur requirement) property from right column.

        4. Expand the Advanced properties by click on the expand button in Creating Data Binding dialog
        5. Click on the button for Value Converter, and select BooleanToVisibilityConverter in System.Windows.Controls

    Then click ok button to close the data binding dialog

    Do these steps because it cannot converter the Bool value to Visibility by default. So we should add a data converter for that

    Thats it!!!!!!!!!
    Wednesday, August 27, 2008 5:33 PM
  • Hi Kaysiehass,

    I think Kesavan_K has misunderstood your question.

    This is relatively simple solution.  Add a event handler for 'GotFocus' Event in XAML file as shown below,

    <TextBox HorizontalAlignment="Left" Margin="37,130,0,175" Width="259" Text="TextBox" TextWrapping="Wrap" GotFocus="GotFocused" x:Name="nameTextBox"/>

    And now in the code behind file add the following code.

    private void GotFocused(object sender, RoutedEventArgs e)
    {
    nameTextBox.SelectAll();
    }


    Hope this answers your question.

    -BALA.

    Saturday, August 30, 2008 12:44 PM