.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

XPView Class

The view that stores data retrieved from persistent objects.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v20.2.dll

Declaration

public class XPView :
    Component,
    ISupportInitialize,
    IBindingList,
    IList,
    ICollection,
    IEnumerable,
    ITypedList,
    IFilteredXtraBindingList,
    IFilteredDataSource,
    IXPClassInfoAndSessionProvider,
    IXPClassInfoProvider,
    IXPDictionaryProvider,
    ISessionProvider,
    IObjectLayerProvider,
    IDataLayerProvider
Public Class XPView
    Inherits Component
    Implements ISupportInitialize,
               IBindingList,
               IList,
               ICollection,
               IEnumerable,
               ITypedList,
               IFilteredXtraBindingList,
               IFilteredDataSource,
               IXPClassInfoAndSessionProvider,
               IXPClassInfoProvider,
               IXPDictionaryProvider,
               ISessionProvider,
               IObjectLayerProvider,
               IDataLayerProvider
public class XPView :
    Component,
    ISupportInitialize,
    IBindingList,
    ICollection,
    IEnumerable,
    IList,
    ITypedList,
    IFilteredXtraBindingList,
    IFilteredDataSource,
    IXPClassInfoAndSessionProvider,
    IXPClassInfoProvider,
    IXPDictionaryProvider,
    ISessionProvider,
    IObjectLayerProvider,
    IDataLayerProvider
Public Class XPView
    Inherits Component
    Implements ISupportInitialize,
               IBindingList,
               ICollection,
               IEnumerable,
               IList,
               ITypedList,
               IFilteredXtraBindingList,
               IFilteredDataSource,
               IXPClassInfoAndSessionProvider,
               IXPClassInfoProvider,
               IXPDictionaryProvider,
               ISessionProvider,
               IObjectLayerProvider,
               IDataLayerProvider

Remarks

Unlike an XPCollection that is populated with persistent objects, the XPView is only intended for displaying data. Its XPView.Session property specifies the data store that the information is retrieved from. If the session isn't specified, the view works with the default session (Session.DefaultSession). The type of retrieved objects is specified by the XPView.ObjectClassInfo property.

The view's columns are stored in the XPView.Properties collection. Note when a new instance of the XPView class is created, its XPView.Properties collection is empty. Therefore, you should manually populate it.

An XPView implements the IBindingList and ITypedList interfaces, so it can serve as a data source for a visual data-aware control (for instance, the XtraGrid).

Create an XPView

When creating an XPView, the session that represents the data store that the information is retrieved from, and the type of retrieved objects, must be specified. If the view is created at runtime, these settings are specified in the view's constructor. Alternatively, you can pass a session via the corresponding parameter of the XPView.ResolveSession event. At design time, use the XPView.Session and XPView.ObjectClassInfo properties, respectively. If the session isn't specified, the view works with the default session (XpoDefault.Session).

After these properties have been specified, you should manually create and customize view columns. An XPView stores its columns within the XPView.Properties collection. Individual columns are represented by a ViewProperty class.

The following example demonstrates how to create a new XPView object and populate its XPView.Properties collection.

using DevExpress.Xpo;
using DevExpress.Data.Filtering;
// ...
private void InitViewColumns(XPView view) {
    view.Properties.AddRange(new ViewProperty[] {   
        new ViewProperty("Trademark", SortDirection.None, "[Trademark]", true, true),
        new ViewProperty("Model", SortDirection.None, "[Model]", true, true),
        new ViewProperty("Price", SortDirection.Ascending, "[Price]", true, true)});
}
// ...
XPView xpView = new XPView(Session.DefaultSession, typeof(WinApplication.Cars));
InitViewColumns(xpView);

The XPView supports various expressions for the ViewProperty.Property (simple, nested, calculated, aggregated, etc.):

using DevExpress.Xpo;
// ...
xpView1.Properties.AddRange(new ViewProperty[] {
  new ViewProperty("Name", SortDirection.None, "[Name]", false, true),
  new ViewProperty("CompanyName", SortDirection.None, "[Customer.CompanyName]", false, true),
  new ViewProperty(("Payment", SortDirection.None, "[Payments].Sum([Amount])", false, true),
  new ViewProperty("EmployeeFullName", SortDirection.None, 
    "Concat([Employee.FirstName], ' ', [Employee.LastName])", false, true)});

Filter an XPView

The XPView allows its records to be filtered. To apply a filter criteria use the XPView.Filter property. To filter a data store, use the XPView.Criteria property. For detailed information, see Filtering.

In this example, the view's data store is filtered to display only those cars which cost less than $100000.

xpView.Criteria = CriteriaOperator.Parse("[Price] < 100000", null);
gridControl1.DataSource = xpView;
NOTE

You can try the functionality described here in the Data Representation | XPView section of the XPO Tutorials demo (C:\Users\Public\Documents\DevExpress Demos 20.2\Components\WinForms\Bin\XpoTutorials.exe).

Member Table

Member Description
XPView.Criteria Specifies the criteria by which the data store will be filtered while the view is being loaded.
XPView.GroupCriteria Specifies the view's grouping criteria.
XPView.ObjectClassInfo Gets or sets the metadata information that describes the type of objects displayed by a view.
XPView.Session The session which is used to load and save persistent objects
XPView.Sorting Provides access to the collection whose elements identify the sorted columns within the view.
XPView.Properties Provides access to the view's column collection.
ViewProperty Represents a column within the view.
ViewRecord Represents a record within the view.

Implements

See Also