Ticket T541705
Visible to All Users

How to cancel grid editing immediately after selecting a record in a lookup editor is canceled

created 8 years ago

[DevExpress Support Team: CLONED FROM T539038: Assistance creating an efficient transaction entry screen in XAF web]
Hi Konstantin,

Thanks for all the assistance so far, I'm getting very close to the desired result.

Your suggestions have fixed the issues I had, but I have a new problem and an improvement I'd like to make:

  1. When a new row is added and the "Product" search shows up, I'd like the user to be able to hit "Esc" at this stage (or press the cancel button) and have the lookup dismissed and the empty row (with null product and zero quantity) automatically cancelled/removed.

Thanks in advance,
Adam

Answers approved by DevExpress Support

created 8 years ago

To accomplish this task do the following.

  1. Handle the InitNewRow event of the ASPxGridView control and register the startup script that will store the gird control's ClientID on the client side:
C#
private void GridView_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e) { DevExpress.ExpressApp.Web.WebWindow.CurrentRequestWindow.RegisterStartupScript("script1", $"window.top.editingGridId = {((DevExpress.Web.ASPxGridView)sender).ClientID}"); }
  1. In the controller which is activated in the popup window, obtain a DialogController controller instance and subscribe to its Canceling event:
C#
DevExpress.ExpressApp.SystemModule.DialogController dialogController = this.Frame.GetController<DevExpress.ExpressApp.SystemModule.DialogController>(); if(dialogController != null) { dialogController.Cancelling += DialogController_Cancelling; }
  1. In this event handler, register the script that will cancel grid control editing:
C#
private void DialogController_Cancelling(object sender, System.EventArgs e) { DevExpress.ExpressApp.Web.WebWindow.CurrentRequestWindow.RegisterStartupScript("script2", @"if(window.top.editingGridId!= null) { window.top.editingGridId.CancelEdit(); }"); }

Let me know if you need further assistance.

    Comments (2)

      Hi Konstantin,

      This will cancel the editing of the GridView when the "Cancel" button is pressed on the lookup, but it does so irrespective of the any data already entered. I'd like to only do it when the data in the GridView row has a certain state (i.e. null product and zero quantity). Because the handler is added to the InitNewRow event, I don't think that will work.

      I think the best solution would be to handle some other GridView event where I set the editingGridId to null once certain data is filled in - but I'm not sure which event.

      Also, in regards to implementing the "Esc" key to dismiss the popup, I tried translating the example at https://www.devexpress.com/Support/Center/Question/Details/S30553/aspxpopupcontrol-provide-the-capability-to-close-a-popup-window-by-pressing-the-esc-button into something at would work with XAF with no luck. If you have any tips, I'd appreciate it.

      Adam

      DevExpress Support Team 8 years ago

        To close a popup window on an Escape key press, use the ASPxPopupControl.CloseOnEscape Property. To access the popup control instance, use the XafPopupWindowControl.CustomizePopupControl Event. To learn how to handle, it refer to the How to: Adjust the Size and Style of Pop-up Dialogs (ASP.NET) article.
        You can register a script that stops gird control editing at the moment when you detect that editing should be stopped. Use the WebWindow.RegisterStartupScript(String, String) Method as it is shown in my previous answer. Alternatively, you can handle the client side event of the control placed into the grid cell and stop grid editing in the event handler. To learn more, please refer to the corresponding control documentation, for example -  ASPxClientSpinEdit members. Let me know how I can assist you further.

        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.