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

[Solved] Setting focus to Insert Row

3 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shanthala Somashekar
Top achievements
Rank 1
Shanthala Somashekar asked on 16 Jul 2009, 09:11 PM
I need to have the insert row visible at all times, so I do something like the following. The problem is after the user tabs through adding data to the row and hits the insert button, when the insert row gets added again during Pre-Render as shown below, I want to be able to put the user focus back into the first cell of the insert row. Note: I use InsertCommand to actually persist the data into the object collection. Please help.

protected

 

void RadGrid1_PreRender(object sender, System.EventArgs e)

 

{

 

 

if (!RadGrid1.MasterTableView.IsItemInserted)

 

{

RadGrid1.MasterTableView.IsItemInserted =

true;

 

RadGrid1.Rebind();

}


}

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Jul 2009, 05:28 AM
Hello Shanthala,

To set focus to the first cell or control of the InsertForm, you have to first access the control from the corresponding column as shown below:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item; 
            TextBox txtbx = (TextBox)insertItem["BoundColumnUniqueName"].Controls[0]; 
            txtbx.Focus(); 
        } 
    } 

Thanks
Princy
0
Shanthala Somashekar
Top achievements
Rank 1
answered on 18 Jul 2009, 05:44 PM
Hi Princy,
  This is still not working. Note, I use inline edit mode and I modified your code to check for GridInsertItem instead but the focus is still not set to the first control on the insert row. Is there anything else I can try?

Thanks
0
Princy
Top achievements
Rank 2
answered on 20 Jul 2009, 04:58 AM
Hello Shanthala,

You would have to replace GridEditFormInsertItem with GridDataInsertItem, when using InPlace edit mode. Try out the following code and see if it helps:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridDataInsertItem insertItem = (GridDataInsertItem)e.Item; 
            TextBox txtbx = (TextBox)insertItem["BoundColumnUniqueName"].Controls[0]; 
            txtbx.Focus(); 
        }  
    } 

Thanks
Princy.
Tags
Grid
Asked by
Shanthala Somashekar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shanthala Somashekar
Top achievements
Rank 1
Share this question
or