This is a migrated thread and some comments may be shown as answers.

Access CellEditTemplate controls from code

4 Answers 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kevin Blanton
Top achievements
Rank 1
Kevin Blanton asked on 23 Feb 2010, 03:49 PM
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

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Feb 2010, 07:21 AM
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.
0
Kevin Blanton
Top achievements
Rank 1
answered on 24 Feb 2010, 02:52 PM
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.
0
Vlad
Telerik team
answered on 01 Mar 2010, 08:40 AM
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.
0
Kevin Blanton
Top achievements
Rank 1
answered on 01 Mar 2010, 06:45 PM
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
Tags
GridView
Asked by
Kevin Blanton
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Kevin Blanton
Top achievements
Rank 1
Share this question
or