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

[Solved] Auto Edit/Focus New Row

2 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 28 Feb 2013, 10:26 PM
When the user clicks the 'New Row' button from the grid's command bar, I'd like to create the row, put it in edit mode, and set focus to the new row's first field.

I've gotten the new row created and put in edit mode but I cannot get it to put the cursor in the edit controls for the row (I have to click inside them to get it started, from that point Tab gets me from field to field and Enter commits as expected).  Is there an example out there on how to do this that I've missed?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 01 Mar 2013, 10:47 AM
Hi,

I guess you want to show cursor in the field in the edit row. Please take look into the following code snippet I tried to focus on the TextBox in Edit mode which is a GridBoundColumn in view mode.

ASPX:
<telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID"></telerik:GridBoundColumn>

C#:
protected void RdGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem form = (GridEditableItem)e.Item;
        TextBox dataField = (TextBox)form["OrderID"].Controls[0]; // This is the First TextBox in my edit row.
        dataField.Focus();
    }
}

Please take a look into this help documentation for more details.

Thanks,
Shinu.
0
J
Top achievements
Rank 1
answered on 01 Mar 2013, 01:38 PM
Awesome.  That worked perfectly.  Thanks.
Tags
Grid
Asked by
J
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
J
Top achievements
Rank 1
Share this question
or