Ticket T386483
Visible to All Users

GridView - How to apply an approach from the E5116 example to edit columns when a new row is being created for Batch Mode

created 9 years ago

[DevExpress Support Team: CLONED FROM E5116: ASPxGridView - How to make some field editors read-only when editing a row and allow their editing when adding a new row]
Hi, i have applied given example in ASP.NET MVC, folllwing is my gridview settings sample partial code:

C#
settings.CellEditorInitialize = (s, e) => { ASPxGridView grid = s as ASPxGridView; ASPxEdit editor = (ASPxEdit)e.Editor; if (e.Column.FieldName == "columnName1" || e.Column.FieldName == "columnName2") { e.Editor.ReadOnly = !grid.IsNewRowEditing; } };

now i can't edit while updating existing row data, that seems perfect.

but i can't edit both columns while creating new row using new button. please help me out here. Thank you in advance.

Show previous comments (1)

    hi Nataly,

    Thanks a lot for your response and great support.

    my problem is: its working fine when:

    C#
    settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow; //if we change editing mode to batch editng mode then this feature is not wokring. settings.SettingsEditing.Mode = GridViewEditingMode.Batch; settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Row; settings.SettingsEditing.BatchEditSettings.StartEditAction = GridViewBatchStartEditAction.DblClick;

    please help me out here, if you need a project sample, please let me know, i will upload a sample project where its not working in given case.
    waiting for your response and my solution.

    DevExpress Support Team 9 years ago

      Hello,

      If you are using the grid in Batch Edit Mode, this solution will not suit you. I suggest that you handle the ASPxClientGridView.BatchEditStartEditing event and analyze the grid's arguments. For example, you can determine if the editing operation is performed for an existing or new row by using visibleIndex (which is -1 for a new row).

      JavaScript
      function OnBatchEditStartEditing(s, e) { if ((e.focusedColumn.fieldName == "ProductName") && (e.visibleIndex >-1)) e.cancel = true; }

      Attached is a screencast illustrating this solution in action. You can refer to the ASPxGridView - Batch Editing - How to cancel editing or disable the editor conditionally example, which describes this approach in greater detail.
      Let me know if you need further clarification regarding this.

        Thank you so much Nataly, it worked as expected. :)

        Answers approved by DevExpress Support

        created 9 years ago (modified 9 years ago)

        Hello,

        If you are using the grid in Batch Edit Mode, this solution will not suit you. I suggest that you handle the ASPxClientGridView.BatchEditStartEditing event and analyze the grid's arguments. For example, you can determine if the editing operation is performed for an existing or new row by using visibleIndex (which is -1 for a new row).
        [JScript] You can refer to the ASPxGridView - Batch Editing - How to cancel editing or disable the editor conditionally example, which describes this approach in greater detail.
        Let me know if you need further clarification regarding this.

        UPDATED:

        The approach strongly depends on your requirements.

        1. If you need to edit each cell one by one (e.g., EditMode is 'Cell'), it is required to use the following handler for the BatchEditStartEditing event:
        JavaScript
        function OnBatchEditStartEditing(s, e) { if ((e.focusedColumn.fieldName == "ProductName") && (e.visibleIndex >-1)) e.cancel = true; }
        1. If you wish to edit the whole row (EditMode is 'Row'), use the following code:
        JavaScript
        function OnBatchEditStartEditing(s, e) { GridView.GetEditor("ProductName").SetEnabled((e.visibleIndex <= -1)); }
          Show previous comments (3)
          DevExpress Support Team 9 years ago

            Hello,

            Thank you for your clarification. Please modify the OnBatchEditStartEditing handler as follows:

            JavaScript
            function OnBatchEditStartEditing(s, e) { GridView.GetEditor("ProductName").SetEnabled((e.visibleIndex <= -1)); }

            You can also hide an editor using the SetVisible method. Attached is a screencast illustrating this solution in action.
            Let me know if this helps.

              Hi,

              I just replaced following line and everything is fine now:

              C#
              settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Row; by settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Cell;

              Thanks a lot for your cooperation.
              Ravi Anand
              :)

              DevExpress Support Team 9 years ago

                Hello Ravi,

                The approach strongly depends on your requirements.

                1. If you need to edit each cell one by one (e.g., EditMode is 'Cell'), it is required to use the following handler for the BatchEditStartEditing event:
                JavaScript
                function OnBatchEditStartEditing(s, e) { if ((e.focusedColumn.fieldName == "ProductName") && (e.visibleIndex >-1)) e.cancel = true; }
                1. If you wish to edit the whole row (EditMode is 'Row'), use the following code:
                JavaScript
                function OnBatchEditStartEditing(s, e) { GridView.GetEditor("ProductName").SetEnabled((e.visibleIndex <= -1)); }

                I hope this information will help you. Let me know if you need further clarification.

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.