How to prevent a DetailView from being shown for a ListView record
Scenario
For certain data forms, a developer needs to limit end-users to editing only through the ListView, i.e. without invoking a separate DetailView. This is usually done by activating the inline editing and MasterDetailMode = ListViewAndDetailView features as described at eXpressApp Framework > Concepts > UI Construction > Views > List View Edit Modes. More real user scenarios are described in this Support Center thread.
For more convenience and flexibility, the following Model Editor extensions are implemented in the example to control this behavior:
- The DefaultShowDetailViewFromListView attribute at the Views node level allows you to control this functionality globally per application via the Model Editor;
- The ShowDetailView attribute at the Views | ListView node level allows you to customize only certain List Views via the Model Editor;
Steps to implement
1. Copy the WinWebSolution.Module\ShowDetailViewFromListViewController.xx file into the YourSolutionName.Module project and rebuild it.
Note: The process of opening a DetailView by double clicking/pressing the Enter key on a record selected in a ListView is managed by the standard DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController class and its ProcessCurrentObjectAction in particular. So, we can disable this Action to accomplish our task. The approaches from the eXpressApp Framework > Concepts > Application Model > Extend and Customize the Application Model in Code, eXpressApp Framework > Concepts > Application Model > Access the Application Model in Code and ActionBase.Enabled Property articles will be used here.
2. For testing purposes, invoke the Model Editor and set the DefaultShowDetailViewFromListView or ShowDetailView properties for the Views or Views | YourObjetType_ListView nodes to False and run the test app to see that a required ListView no longer opens a DetailView in the aforementioned scenario.
Note.
We added some optimizations intended to improve the DetailView opening performance. This optimization depends on the default behavior - the ListView item click opens a DetailView. We suggest that you disable this optimization if you suppress DetailView opening to avoid issues. To disable the optimization, add the following code to the App_Start event handler:
[C#]
DevExpress.ExpressApp.Web.WebApplication.OptimizationSettings.AllowFastProcessListViewRecordActions = false;
[VB]
DevExpress.ExpressApp.Web.WebApplication.OptimizationSettings.AllowFastProcessListViewRecordActions = False
IMPORTANT NOTES
This article covers only the case when a DetailView is shown from the ListView after a User double clicks/presses the enter key on a record. Other scenarios should be handled separately by extending the code of this controller. For example, if you do not want to show a DetailView after a new object is created via the New Action, you can handle the NewObjectViewController.ObjectCreating event and set its ObjectCreatingEventArgs.ShowDetailView property to False. However, this is outside the purpose of this article.