RADGRID : Do Set Focus in In-Mode-Editing

14 posts, 0 answers
  1. soo
    soo avatar
    25 posts
    Member since:
    Oct 2007

    Posted 27 May 2008 Link to this post

    Hi,

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

    How to do that?

    Please advice.

    Thanks.
    Soo
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 May 2008 Link to this post

    Hi,

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

    Thanks
    Princy.
  3. soo
    soo avatar
    25 posts
    Member since:
    Oct 2007

    Posted 28 May 2008 Link to this post

    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
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 May 2008 Link to this post

    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.
  5. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 28 May 2008 Link to this post

    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
  6. soo
    soo avatar
    25 posts
    Member since:
    Oct 2007

    Posted 28 May 2008 Link to this post

    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

  7. Andy
    Andy avatar
    107 posts
    Member since:
    Sep 2010

    Posted 13 Jul 2011 Link to this post

    Hi Soo,

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

    Thanks.

    Andy.
  8. Andy
    Andy avatar
    107 posts
    Member since:
    Sep 2010

    Posted 14 Jul 2011 Link to this post

    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.



  9. Stacy
    Stacy avatar
    116 posts
    Member since:
    Dec 2010

    Posted 10 Jun 2013 Link to this post

    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.
  10. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jun 2013 Link to this post

    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.
  11. Stacy
    Stacy avatar
    116 posts
    Member since:
    Dec 2010

    Posted 11 Jun 2013 Link to this post

    I ended up having to use "e.Item.FindControl" to find my control

     

     

     

  12. Kiran
    Kiran  avatar
    31 posts
    Member since:
    Oct 2018

    Posted 08 Oct 2018 Link to this post

    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

     

  13. Attila Antal
    Admin
    Attila Antal avatar
    246 posts

    Posted 10 Oct 2018 Link to this post

    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.
Back to Top