This example demonstrates how to declare a collection property of a persistent type in a non-persistent class and display it in the UI.
Implementation Details
- Create a non-persistent class that implements entry fields and use PopupWindowShowAction to display a Detail View of the class instance in a pop-up window.
- Extend the class with a collection property that allows user to select items from a list. To read the selection in the Action's
Execute
event, access theListPropertyEditor
that is the nested List View. - Handle the
ObjectSpaceCreated
event to create anObjectSpace
that can handle persistent objects (the collection property you added). Review the following documentation article for additional information: How to: Show Persistent Objects in a Non-Persistent Object's View - The pop-up window invoked by the PopupWindowShowAction contains the OK and Cancel buttons implemented in the DialogController. To add other Actions, create a controller for the dialog class and set the
Category
toPopupActions
.
Files to Review
Documentation
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Editors;
using ComplexDialogSample.Module.BusinessObjects;
namespace ComplexDialogSample.Module.Controllers {
public class MyController : ObjectViewController<ListView, Office> {
public MyController() {
PopupWindowShowAction action = new PopupWindowShowAction(this, "AssignJobs", PredefinedCategory.RecordEdit);
action.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
action.CustomizePopupWindowParams += new CustomizePopupWindowParamsEventHandler(action_CustomizePopupWindowParams);
action.Execute += new PopupWindowShowActionExecuteEventHandler(action_Execute);
}
void action_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
IObjectSpace os = Application.CreateObjectSpace(typeof(OrderTemplate));
e.Context = TemplateContext.PopupWindow;
var template = os.CreateObject<OrderTemplate>();
e.View = Application.CreateDetailView(os, template);
}
void action_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) {
OrderTemplate parameters = (OrderTemplate)e.PopupWindow.View.CurrentObject;
ListPropertyEditor listPropertyEditor = ((DetailView)e.PopupWindow.View).FindItem("Services") as ListPropertyEditor;
IObjectSpace os = Application.CreateObjectSpace(typeof(Team));
Team team = os.GetObject<Team>(parameters.Team);
foreach (Office b in e.SelectedObjects) {
foreach (Service service in listPropertyEditor.ListView.SelectedObjects) {
Order order = os.CreateObject<Order>();
order.DueDate = parameters.DueDate;
order.Team = team;
order.Office = os.GetObject<Office>(b);
order.Service = os.GetObject<Service>(service);
}
}
os.CommitChanges();
}
}
}
C#using System.ComponentModel;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Updating;
using DevExpress.ExpressApp.Model.Core;
using DevExpress.ExpressApp.Model.DomainLogics;
using DevExpress.ExpressApp.Model.NodeGenerators;
namespace ComplexDialogEF.Module;
// For more typical usage scenarios, be sure to check out https://docs.devexpress.com/eXpressAppFramework/DevExpress.ExpressApp.ModuleBase.
public sealed class ComplexDialogEFModule : ModuleBase {
public ComplexDialogEFModule() {
//
// ComplexDialogEFModule
//
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.SystemModule.SystemModule));
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule));
}
public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) {
ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
return new ModuleUpdater[] { updater };
}
public override void Setup(XafApplication application) {
base.Setup(application);
application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
// Manage various aspects of the application UI and behavior at the module level.
}
private void Application_ObjectSpaceCreated(object sender, ObjectSpaceCreatedEventArgs e) {
CompositeObjectSpace compositeObjectSpace = e.ObjectSpace as CompositeObjectSpace;
if (compositeObjectSpace != null) {
if (!(compositeObjectSpace.Owner is CompositeObjectSpace)) {
compositeObjectSpace.PopulateAdditionalObjectSpaces((XafApplication)sender);
}
}
}
}