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."
How to edit an object in the DetailView opened by a row click from a nested ListView (CollectionsEditMode = ViewEditMode.Edit)
Answers approved by DevExpress Support
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.
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.
@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.