Access CellEditTemplate controls from code

5 posts, 0 answers
  1. Kevin Blanton
    Kevin Blanton avatar
    9 posts
    Member since:
    Sep 2012

    Posted 23 Feb 2010 Link to this post

    We have a colunm in a RadGridView that we have setup using a CellEditTemplate.

    This template has a single textbox in it that utilizes some of the textbox events such as TextChanged to do some custom validation and other things.  At the end of this event we sometimes have need to change the focus to the same column in the next row (depending on the data entered).

    Once we have set this row into edit mode we would like to set the exact cursor position (SelectionStart) in the textbox.

    I can successfully change the row and put the proper cell into edit mode, but I can not seem to figure out how to access the textbox so that I can set the SelectionStart property.

    I tired using myGrid.CurrentCell.ChildrenOfType<TextBox>() but it does not return any controls.

    How can I can access to the textbox from code so that I can set this property?

    Kevin
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 24 Feb 2010 Link to this post

    Hi Kevin,

    You can use Loaded event of the TextBox itself similar to our demo:
    http://demos.telerik.com/silverlight/#GridView/CellEditTemplate

    Kind regards,
    Vlad
    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. DevCraft banner
  4. Kevin Blanton
    Kevin Blanton avatar
    9 posts
    Member since:
    Sep 2012

    Posted 24 Feb 2010 Link to this post

    I appreciate yourresponse here.  I should have made it clear that I attempted to use the Loaded event before I posted.  However, it is not as simple as that. This need to occur from a custom routine that is called from the textchanged event of a textbox that is in the cell edit template.  In order for me to use this I will have to set some form level variables from my custom routine so that the Loaded event will have access to the cursor positon that I want to set.  This seems to be a 'rigged' solution to my problem. 

    The textchanged event is being used to mimic an word wrap type of functionality that will automaticlly wrap the text entered for a description to the next row.  I really need a way to to gain access to the textbox inside the current cell edit template and set the selectionstart property from there.  

    Surely there is some way that I can get the textbox instance other than using the loaded event so that my custom routine can set the selection start or any other property that I may need to set.  This is the only piece that I am missing to make my process work.
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Mar 2010 Link to this post

    Hello Kevin,

    You can get the parent cell from this event using ParentOfType:

    var cell = ((TextBox)sender).ParentOfType<GridViewCell>();

    and desired child using ChildrenOfType:

    var otherElement = cell.ChildrenOfType<YourControlType>().FirstOrDefault();

    Regards,
    Vlad
    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.
  6. Kevin Blanton
    Kevin Blanton avatar
    9 posts
    Member since:
    Sep 2012

    Posted 01 Mar 2010 Link to this post

    I was able to capture the info that I needed in the Loaded event and store it in a form level variable for access at a later point in my process outside the Loaded Event.

    However, please add this to the requested features list.  It would be EXTREMELY helpful to be able to access the current edit control from a template OUTSIDE of using the Loaded event.  It is not very good coding practice to use a form level variable for this.

    Kevin
Back to Top
DevCraft banner