XafApplication.CreateListView(String, CollectionSourceBase, Boolean) Method
Creates a List View based on information from the Application Model‘s Views | View node specified by the listViewId parameter.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
#Declaration
public ListView CreateListView(
string listViewId,
CollectionSourceBase collectionSource,
bool isRoot
)
#Parameters
Name | Type | Description |
---|---|---|
list |
String | A string that represents an identifier of the Application Model node that serves as an information source for creating a new List View. |
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.
If you need to create a List View from information specified in a custom Application Model node, use the CreateListView(IModelListView, CollectionSourceBase, Boolean) overload.
The listViewId parameter should equal the Id property of an existing IModelListView node from the Application Model’s Views node. Use this parameter to define which model should be used for the created View.
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.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);
CollectionSourceBase collectionSource = Application.CreateCollectionSource(
newObjectSpace, objectType, listViewId);
e.View = Application.CreateListView(listViewId, collectionSource, true);
}
}