Ticket B151776
Visible to All Users

How to edit an object in the DetailView opened by a row click from a nested ListView (CollectionsEditMode = ViewEditMode.Edit)

created 15 years ago

Proposed Solution:
Marcello Gesmundo wrote:
"HMO the default behavior is better if you add a controller to always open in edit mode the popup window (if CollectionEditMode = Edit) when the user clic on the row of the detail collection and the master object is in edit mode. I hope i have been able to explain my thought."

Answers approved by DevExpress Support

created 15 years ago (modified 8 years ago)

Currently, you can consider one of the following solutions to always open an editable child DetailView in the same main window after clicking on a nested ListView record inside an editable parent DetailView as opposed to the default popup opening with a read-only view. To see the difference between these solutions and the default Web UI behavior, use our MainDemo.Web app, edit a contact in DetailView and then try to open its existing tasks by clicking on them.

1. Implement a custom ViewController that will intercept the default behavior of the https://documentation.devexpress.com/#eXpressAppFramework/clsDevExpressExpressAppSystemModuleListViewProcessCurrentObjectControllertopic class and always make the opened DetailView editable. Consider the following pseudo code (tested with our MainDemo.Web app):

C#
using DevExpress.ExpressApp; using MainDemo.Module.BusinessObjects; using DevExpress.ExpressApp.SystemModule; namespace MainDemo.Module.Web { public class Class2: ObjectViewController<ListView, DemoTask> { public Class2() { TargetViewId = "Contact_Tasks_ListView"; } protected override void OnActivated() { base.OnActivated(); DetailView parentDetailView = (DetailView)((NestedFrame)Frame).ViewItem.View; if(parentDetailView.ViewEditMode == DevExpress.ExpressApp.Editors.ViewEditMode.Edit) { ListViewProcessCurrentObjectController controller = Frame.GetController<ListViewProcessCurrentObjectController>(); if(controller != null) { controller.CustomizeShowViewParameters += Class2_CustomizeShowViewParameters; } } } void Class2_CustomizeShowViewParameters(object sender, CustomizeShowViewParametersEventArgs e) { ((DetailView)e.ShowViewParameters.CreatedView).ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit; } } }

You can learn more on this implementation from the Concepts > Extend Functionality > Customize Controllers and Actions and eXpressApp Framework > Concepts > Extend Functionality > Built-in Controllers and Actions  help articles.

2. Implement a custom ShowViewStrategy with the overridden ShowViewFromNestedView  method that will globally change the default behavior for showing views from a nested Frame. Consider the code below, which can be added into the YourSolutionName.Web/Global.asax.cs file:

C#
using System; using System.Web; using DevExpress.Web; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Xpo; using DevExpress.ExpressApp.Web; using DevExpress.Persistent.Base; using System.Collections.Generic; using DevExpress.ExpressApp.Editors; namespace MainDemo.Web { public class MyShowViewStrategy_B151776 : ShowViewStrategy { public MyShowViewStrategy_B151776(XafApplication application) : base(application) { } protected override void ShowViewFromNestedView(ShowViewParameters parameters, ShowViewSource showViewSource) { NestedFrame nestedFrame = showViewSource.SourceFrame as NestedFrame; bool isParentDetailViewEditable = (nestedFrame != null) && (nestedFrame.ViewItem != null) && (nestedFrame.ViewItem.View is DetailView) && (((DetailView)nestedFrame.ViewItem.View).ViewEditMode == ViewEditMode.Edit); bool isDetailViewToBeShown = parameters.CreatedView is DetailView; bool isDetailViewShownFromListViewAction = showViewSource.SourceAction != null && showViewSource.SourceAction.Id == DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController.ListViewShowObjectActionId; if(isDetailViewToBeShown && isParentDetailViewEditable && isDetailViewShownFromListViewAction) { ((DetailView)parameters.CreatedView).ViewEditMode = ViewEditMode.Edit; Application.MainWindow.SetView(parameters.CreatedView, showViewSource.SourceFrame); } else { base.ShowViewFromNestedView(parameters, showViewSource); } } } public class Global : System.Web.HttpApplication { ... protected void Session_Start(object sender, EventArgs e) { Tracing.Initialize(); WebApplication.SetInstance(Session, new MainDemoWebApplication()); WebApplication.Instance.ShowViewStrategy = new MyShowViewStrategy_B151776(WebApplication.Instance); ...

You can learn more on this implementation from the XafApplication > ShowViewStrategy and DevExpress.ExpressApp > ShowViewStrategyBase help articles.

NOTE: these are not complete and generic solutions that apply to each and every standard XAF scenario, and you will likely need to modify and test them further according to your own business needs or situations.

    Comments (2)

      Hi Dennis,
      I have implemented the above code in my Web XAF project and it gives me error while executing this line Application.MainWindow.SetView(parameters.CreatedView, showViewSource.SourceFrame);
      Error is: Exception occurs while assigning the 'DetailView, ID:JournalVoucherDetails_DetailView' view to WebWindow:
      BTW, i have implemented the MyShowViewStrategy_B151776 in Global.asax page.

      Dennis Garavsky (DevExpress) 11 years ago

        @Mohammed:
        Please check out the InnerException within the eXpressAppFramework.log file as it should describe the actual reason for this behavior. If you are not able to resolve the problem by this diagnostic information yourself, then please create a separate ticket in the Support Center and post your problematic sample there, so we can assist you further. Thanks.

        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.