Skip to main content
.NET 8.0+

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
listViewId String

A string that represents an identifier of the Application Model node that serves as an information source for creating a new List View.

collectionSource CollectionSourceBase

A CollectionSourceBase object that represents the storage for the object to be displayed by the new List View. This object is assigned to the ListView.CollectionSource property.

isRoot Boolean

true, if the created List View is independent and owns the Object Space assigned to the View.ObjectSpace property; false, if the created List View is nested to another root View that owns the Object Space. This value is assigned to the View.IsRoot property.

Returns

Type Description
ListView

A ListView object used to display the collection of objects specified by the collectionSource parameter.

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.ObjectSpace for the creation of a new root View in it. Instead, create a new Object Space using the XafApplication.CreateObjectSpace method for the new root 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);
    }
}
See Also