Switching edit mode clicking on different buttons

5 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 16 Jul 2013 Link to this post

    What I'm trying to accomplish is very simple (but I can't seem to find a way on my own).
    I would like to open a row with EditMode="InPlace" with double click on that row, while I would like to open the whole form editing if I click on a command button in the grid (for example the GridEditCommandColumn button).

    To open the row in edit mode on double click I just:
    <ClientEvents OnRowDblClick="RowDblClick" />
     
    ' and then...
     
        <telerik:RadScriptBlock runat="server">
            <script type="text/javascript">
                function RowDblClick(sender, eventArgs) {
                    sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
                }
            </script>
        </telerik:RadScriptBlock>

    The problem is how to switch from one edit mode to another in code behind based on how the user accessed edit mod, from double clik or from GridEditCommandColumn button.
    If I put "InPlace" as default edit mode and then in code behind:
    Protected Sub RadGrid1_EditCommand(sender As Object, e As GridCommandEventArgs)
        RadGrid1.MasterTableView.EditMode = GridEditMode.EditForms
    End Sub

    This works and open the form edit mode. The problem is.. If I for example issue a custom ItemCommand for one of the two, let's say "FullEditCommand" and there I switch to "GridEditMode.EditForms", how can I then retrigger the Edit command to go on with the editing?
    Alsow I have to explicitly set "GridEditMode.InPlace" when I access editing with double click on a row, otherwise the grid would remember the last setting so I cannot pass from one to another.

    Any hint pointing in the right direction is much appreciated as always. Thanks in advance.
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 19 Jul 2013 Link to this post

    Hello Massimiliano,

    Thank you for contacting us.

    In order to change the EditMode of the RadGrid depending on the user behavior, the best solution is to fire custom commands on client-side. Then on server-side you can check which command is fired in the gird ItemCommand event handler and change the edit mode as you please.

    For your scenario I have prepared a simple project with declaratively set EditMode to "EditForms" with the following client-side and server-side logic:
    • Double click on grid row fires custom command "InPlaceMode";
    • In ItemCommand server-side event handler, if the CommandName is "InPlaceMode", the current edit item "Edit" property is changed to false (closing the opened edit form);
    • The double clicked item Edit property is set to True;
    • Rebind the grid.

    If we can be of any further assistance, please feel free to get back to us.

    Best Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 19 Jul 2013 Link to this post

    Thank you Konstantin, you were precious.
    Going to try this asap. If I don't reply back here it means it is working as intended.
  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 22 Jul 2013 Link to this post

    Hi Massimiliano,

    I assume that you have successfully implemented the suggested  functionality.

    Best Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 22 Jul 2013 Link to this post

    Working like a charm, thanks again.
    Here is my complete code behind (vb.net) that may be useful to other users:

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
        RadGrid1.MasterTableView.EditMode = GridEditMode.EditForms
     
        Select Case e.CommandName
            Case "EditInPlace"
                RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace
                For i As Integer = 0 To RadGrid1.MasterTableView.ChildEditItems.Count - 1
                    RadGrid1.MasterTableView.ChildEditItems(i).Edit = False
                Next
                RadGrid1.MasterTableView.Items(e.CommandArgument.ToString()).Edit = True
                RadGrid1.Rebind()
            Case "ClearFilters"
                For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                    column.CurrentFilterFunction = GridKnownFunction.NoFilter
                    column.CurrentFilterValue = String.Empty
                Next
                RadGrid1.MasterTableView.FilterExpression = String.Empty
                RadGrid1.MasterTableView.Rebind()
            Case "ClearSorting"
                For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                    column.SortExpression = ""
                Next
                RadGrid1.MasterTableView.SortExpressions.Clear()
                RadGrid1.MasterTableView.Rebind()
            Case "Ungroup"
                RadGrid1.MasterTableView.GroupByExpressions.Clear()
                RadGrid1.MasterTableView.Rebind()
        End Select
    End Sub
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017