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

Set focus on row in grid after update

3 Answers 889 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 10 Mar 2015, 07:25 PM
I have searched the forums but hve not found anything exactly like this, so forgive if I'm asking a question that's already been answered.

I have a grid where the record is in edit mode. The user tabs from one textbox to the next, entering data. the last tab stop is the check button. When the user tabs to the check button and then hits enter, the OnUpdate code fires. But the row is updated and the row closes and the cursor goes to the next tab stop (in this case, the beginning of the page). I have used SetFocus(AcctHeaderDetail.MasterTableView) to keep the focus on the grid. It does, but the focus goes to the insert button in the grid.

What I need to do is keep the focus in the grid in such a way that the user is able to use the down arrow to move down to the next record, hit Enter and the row opens up for editing.

Ho do I manage control of what object receives the focus after the OnUpdate code behind executes?

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 13 Mar 2015, 11:40 AM
Hello Thomas,

In order to implement this functionality you can use the following approach. When updating a record you can keep the index of the currently updated item. Then, in the PreRender event of RadGrid you can use that index and set the next item as focused.

The following markup outlines the approach:


int itemIndex;
 
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    // update logic
 
    itemIndex = editItem.ParentItem.ItemIndex;
}


protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (itemIndex != RadGrid1.Items.Count -1)
    {
        RadGrid1.Items[itemIndex + 1].Focus();   
    }
     
}




Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Thomas
Top achievements
Rank 1
answered on 13 Mar 2015, 05:17 PM
GridEditableItem editItem = e.Item as GridEditableItem;

itemIndex = editItem.ParentItem.ItemIndex;

This code produces the intellisense error that Telerik.Web.UI.GridEditableItem does not contain a definition for ParentItem
0
Viktor Tachev
Telerik team
answered on 17 Mar 2015, 01:50 PM
Hi Thomas,

If the EditMode property is set to EditForms you can cast the Item to GridEditFormItem.

int itemIndex;
 
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    var editItem = e.Item as GridEditFormItem;
         
    itemIndex = editItem.ParentItem.ItemIndex;
}

In case you are using InPlace EditMode you should cast the Item to GridDataItem:

int itemIndex;
 
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    var editItem = e.Item as GridDataItem;
     
    itemIndex = editItem.ParentItem.ItemIndex;
}

If you would like additional information on different EditModes and how to access the edit items you would find the following articles interesting:


Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Thomas
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or