How can I set focus to text box inside a datatemplate?

6 posts, 0 answers
  1. Jerry Kurata
    Jerry Kurata avatar
    92 posts
    Member since:
    Feb 2010

    Posted 27 May 2011 Link to this post

    Hi,

    I have a datatemplate for each row in the grid.  I am trying to ensure that when the user creates a new row they are left in edit mode in a text box that is part of the template.  Does anyone have an example I can review?

    One potential complexity is that my data template is defined in a ResourceDictionary.

    thanks,

    jerry
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 01 Jun 2011 Link to this post

    Hello Jerry Kurata,

    Would you please shed some more light on your custom template structure? Where do you intend to place this DataTemplate? Meanwhile, you may refer to our Custom Row Layout example. it might prove useful.

    Kind regards,
    Ivan Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jerry Kurata
    Jerry Kurata avatar
    92 posts
    Member since:
    Feb 2010

    Posted 01 Jun 2011 Link to this post

    Hi,

    The datatemplate would be used to represent the cell content such as:
    <DataTemplate>
          <TextBox x:name="txtvalue" width="100"  />
    </DataTemplate>
    The row containing the cell would be added to the grid by a user dropping onto the grid.  At that time we create the row and want to have the focus in the textbox in the newly created row so the user can start entering text without having to select the textbox with their mouse.

    Thanks,

    Jerry
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 05 Jun 2011 Link to this post

    Hi Jerry Kurata,

    As you are using a quite simple cell template without changing the internal template structure of RadGridView, I would advise you to execute the RadGridViewCommands.BeginInsert command, when you are about to add a new row to the grid. If I have understood you requirements properly, this approach will save you a lot of effort and the results will be quite similar to the desired ones.

    Best wishes,
    Ivan Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Anirban
    Anirban avatar
    8 posts
    Member since:
    Jun 2011

    Posted 29 Sep 2011 Link to this post

    Hi,

    I am having the same issue. I have a text box inside a DataTemplate . The TextBox is placed inside a StackPanel and the DataTemplate is been accessed to the View through Merged Dictionary. Now when the View loads up, the Focus should be set on that TextBox .

    It would be great if you could provide some details on this.

    Thanks,
    Anirban
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 04 Oct 2011 Link to this post

    Hello Anirban,

    Unfortunately there is no clean approach to subscribe to any event of your DataTemplate's elements, as it is stored in a ResourceDictionary. Would you please clarify where exactly do you load this template in RadGridView, so that we could propose you a solution that utilizes a proper RadGridView event? 

    Greetings,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top