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

RADGRID : Do Set Focus in In-Mode-Editing

13 Answers 393 Views
Grid
This is a migrated thread and some comments may be shown as answers.
soo
Top achievements
Rank 1
soo asked on 27 May 2008, 06:22 AM
Hi,

May i know possible to do set focus inside in-mode editng textbox in radgrid?

How to do that?

Please advice.

Thanks.
Soo

13 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 May 2008, 07:14 AM
Hi,

Check out the following help document link.
Focus the text boxes in the edit control

Thanks
Princy.
0
soo
Top achievements
Rank 1
answered on 28 May 2008, 09:49 AM
Hi Princy,

I'm not able to set focus to the first field of the textbox when i click on "add new items" link during inline edit mode in radgid.

Can you give me more clear example?

Thanks alot.

Regards,
Soo
0
Princy
Top achievements
Rank 2
answered on 28 May 2008, 10:26 AM
Hi Soo,

Try the following code snippet to set the Focus for the TextBox in Insert mode.

CS:
 protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted))  
        {  
            GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item;  
            TextBox txtbx = (TextBox)insertitem["ProductName"].Controls[0];  
            txtbx.Focus();  
        }  
 
    } 


Thanks
Princy.
0
Yavor
Telerik team
answered on 28 May 2008, 10:40 AM
Hello soo,

You can use code like the one below to achieve your task:

.cs
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)  
        {  
            GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;  
            (insertItem["LastName"].Controls[0] as TextBox).Focus();  
        }  
    } 

I hope this helps.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
soo
Top achievements
Rank 1
answered on 29 May 2008, 02:21 AM
Hi Princy and Yavor,

Thanks of your help. I had tried your both solution but i'm not able to set focus to the textbox using txtBox.focus()

Finally, I get this done by trying to set the radgrid.enabledAjax = false first. Then manually add ajax to the radgrid using radajaxmanager.

Then, inside the itemdatabound, i put this code

RadAjaxManager1.FocusControl(txtBox)

Anyway, your both code really help alots. Thanks again.

Regards,
Soo

0
Andy
Top achievements
Rank 1
answered on 13 Jul 2011, 04:31 PM
Hi Soo,

I am having this problem.
Could you please give more detailed code?

Thanks.

Andy.
0
Andy
Top achievements
Rank 1
answered on 14 Jul 2011, 03:49 PM
Hi all,

Here is the code 
Protected Sub dgList_ItemCreated(ByVal sender As System.ObjectByVal As Telerik.Web.UI.GridItemEventArgs) Handles dgList.ItemCreated
 
 If (TypeOf e.Item Is GridDataInsertItem And e.Item.IsInEditMode) Then
            Dim txtCarNumberFocus As RadTextBox = e.Item.FindControl("your_RadTextboxId")
            RadAjaxManager1.FocusControl(txtCarNumberFocus.ClientID + "_text")
            e.Item.Selected = True
  End If
 
End Sub
Note: This code just works with RadTextbox, not asp:Textbox

Andy.



0
Stacy
Top achievements
Rank 1
answered on 10 Jun 2013, 05:28 PM
When I try:

protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
   {  
       if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted))  
       {  
           GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item;  
           TextBox txtbx = (TextBox)insertitem["ProductName"].Controls[0];  
           txtbx.Focus();  
       }  
  
   

I get this error:

Item in insert mode does implement indexer only when the edit form is autogenerated

Any ideas how I can get past this?  I am trying to set focus to an item when in edit mode.
0
Shinu
Top achievements
Rank 2
answered on 11 Jun 2013, 03:56 AM
Hi,

Unfortunately I couldn't replicate the issue at my end. Please check the following code snippet I tried.

ASPX:
<telerik:RadGrid ID="Radgrid1" runat="server" OnItemDataBound="Radgrid1_ItemDataBound">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

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["OrderID"].Controls[0];
        txtbx.Focus();
    }  
}

Please provide your code snippet if it doesn't help.

Thanks,
Shinu.
0
Stacy
Top achievements
Rank 1
answered on 11 Jun 2013, 01:53 PM
I ended up having to use "e.Item.FindControl" to find my control

 

 

 

0
Stacy
Top achievements
Rank 1
answered on 11 Jun 2013, 01:53 PM
0
Kiran
Top achievements
Rank 1
answered on 08 Oct 2018, 06:20 PM

Not able to set focus in Batch edit mode.

ASPX:

<telerik:GridTemplateColumn UniqueName="OPR_COUNT" DataField="OPR_COUNT" HeaderText="OPR_COUNT" Visible="TRUE" HeaderStyle-Width="20px"  >
                                <ItemTemplate>
                                      <%#DataBinder.Eval(Container.DataItem, "OPR_COUNT")%>
                                 </ItemTemplate>
                            <EditItemTemplate >                              
                                <Telerik:radTextBox ID="TextBox1" Text='<%# Bind("OPR_COUNT")%>' BackColor ="Black" ForeColor="White"  runat="server" Width="70px" 
                                    Font-Size="Large"     >
                                    <ClientEvents  />
                                </Telerik:radTextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="<b>*REQUIRED<b>" ControlToValidate="TextBox1" ForeColor="Aqua">
                                </asp:RequiredFieldValidator>                        
                            </EditItemTemplate>  
                       
               </telerik:GridTemplateColumn>

 

VB:

 

Protected Sub rgRtnDetail_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rgRtnDetail.ItemDataBound
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim value = DataBinder.Eval(item.DataItem, "OPR_COUNT")
            If value = 0 Then
                item.ForeColor = Color.Red
            Else
                item.ForeColor = Color.Lime
            End If
        End If

        'If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
        '    Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)
        '    Dim tbox As RadTextBox = TryCast(item("OPR_COUNT").Controls(0), RadTextBox)
        '    tbox.Focus()
        'End If

        'If TypeOf e.Item Is GridDataItem AndAlso e.Item.IsInEditMode Then
        '    Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        '    Dim txtb As RadTextBox = DirectCast(item("OPR_COUNT").Controls(0), RadTextBox)
        '    txtb.Focus()
        'End If

        If (TypeOf e.Item Is GridEditFormInsertItem) AndAlso (e.Item.OwnerTableView.IsItemInserted) Then
            Dim insertitem As GridEditFormInsertItem = CType(e.Item, GridEditFormInsertItem)
            Dim txtbx As TextBox = CType(insertitem("OPR_COUNT").Controls(0), TextBox)
            txtbx.Focus()
        End If

    End Sub

 

0
Attila Antal
Telerik team
answered on 10 Oct 2018, 06:30 PM
Hi Kiran,

I can see that you have opened a formal support ticket for this issue. I advise that we discuss the details in that ticket and once we have the solution, we will share it in this thread,  for the community.

Thread related to: RadComboBox focus retained when clicking other control

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
soo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
soo
Top achievements
Rank 1
Yavor
Telerik team
Andy
Top achievements
Rank 1
Stacy
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Kiran
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or