XafApplication.CreateListView(IModelListView, CollectionSourceBase, Boolean) Method
Creates a List View based on the information from the Application Model‘s node specified by the modelListView parameter.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
#Declaration
public ListView CreateListView(
IModelListView modelListView,
CollectionSourceBase collectionSource,
bool isRoot
)
#Parameters
Name | Type | Description |
---|---|---|
model |
IModel |
An IModel |
collection |
Collection |
A Collection |
is |
Boolean | true, if the created List View is independent and owns the Object Space assigned to the View. |
#Returns
Type | Description |
---|---|
List |
A List |
#Remarks
Use this method to create and initialize a List View according to values passed as parameters.
To create a Collection Source for the collectionSource parameter, use the XafApplication.CreateCollectionSource method. The created Collection Source can be customized to change objects displayed in the created List View. For example, the List View’s records can be filtered through the CollectionSourceBase.Criteria property. With this CreateListView overload, the View.ObjectSpace property is initialized using the CollectionSourceBase.ObjectSpace value.
Pass true to the isRoot parameter if the new View owns the Object Space passed to the objectSpace parameter. If this Object Space already belongs to another View, pass false. Note that certain Controllers and Actions are deactivated in this case. See View.IsRoot for additional information. To avoid this, use the XafApplication.CreateObjectSpace or XafApplication.CreateNestedObjectSpace method to create a new Object Space, and pass this Object Space to the objectSpace parameter.
Note
Do not use another View’s View.
The following example creates a Lookup List View and displays it via a PopupWindowShowAction.
using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
// ...
public class ShowListViewController : WindowController {
public ShowListViewController() {
PopupWindowShowAction showListViewAction = new PopupWindowShowAction(
this, "ShowListView", PredefinedCategory.Edit);
showListViewAction.CustomizePopupWindowParams += ShowListViewAction_CustomizePopupWindowParams;
}
private void ShowListViewAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
Type objectType = typeof(Person);
IObjectSpace newObjectSpace = Application.CreateObjectSpace(objectType);
string listViewId = Application.FindLookupListViewId(objectType);
IModelListView modelListView = (IModelListView)Application.FindModelView(listViewId);
CollectionSourceBase collectionSource = Application.CreateCollectionSource(
newObjectSpace, objectType, listViewId);
e.View = Application.CreateListView(modelListView, collectionSource, true);
}
}