Search This Blog

Monday, September 12, 2016

Why can a DetailView be not editable or display empty values?

This small thing may hit even experienced XAFers, so I want to post this tip here for the future. In fact, I created a corresponding KB article a few months ago, but forgot to promote it in my blog. So, here we go:

1. You are creating a new detail form via the XafApplication.CreateDetailView API in a Web application, but it does not allow users to enter any information; e.g., they can't write/select anything into/from lookups. The View controls also look "readonly" or disabled. The same code produces an editable DetailView in WinForms, though.
2. Same readonly View editors as in the previous point, but the controls do not display any values either + the code does not work in both WinForms and ASP.NET apps.
3. You are opening a DetailView of an object that was deleted by another user. This way, this behavior is normal and expected as removed data can no longer be edited.

1. Make sure you have set the DetailView.ViewEditMode property to the DevExpress.ExpressApp.Editors.ViewEditMode.Edit value. For example, check the snippet from this KB Article:
... DetailView dv = Application.CreateDetailView(os, obj); dv.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;//!!! e.ShowViewParameters.CreatedView = dv; ...
It's a known specificity of the XAF ASP.NET WebForms UI and common Web UI in general that detail forms have two modes: view and edit. There is no such behavior in WinForms, where DetailView.ViewEditMode is always Edit by default.

 Make sure you are using the XafApplication.CreateDetailView method overload from this list that accepts the "object obj" parameter and this parameter is actually not null. Otherwise, an empty detail form will be created by default.
Alternatively, you can explicitly set the DetailView.CurrentObject property to a non-empty object value; e.g.:
... DetailView dv = Application.CreateDetailView(objectSpace, "DemoTask_DetailView", true); dv.CurrentObject = objectSpace.CreateObject<DemoTask>(); ...
Use this approach caution when assigning a new object to an existing DetailView, which is already set to Frame and for which Controllers are activated; e.g., when customizing an embedded DetailView as part of a DashboardViewItem. In this case, handling the XafApplication.DetailViewCreating event can be a better choice (learn more...). 

In all cases make sure the resultant value of the View.AllowEdit property as well as of the individual PropertyEditor.AllowEdit property is set to True. If it is false, you can diagnose the reason by following the Determine Why an Action, Controller or Editor is Inactive article. 

No comments:

Post a Comment