Skip to main content
A newer version of this page is available. .

XPView Concepts

  • 3 minutes to read

The XPView is represented by the XPView class. It is intended to be used only to display data. It allows arbitrary combinations of calculated and aggregated values to be retrieved from the object model. 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).

Creating 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)});

Filtering 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 the topics in the Querying a Data Store section.

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 19.2\Components\WinForms\Bin\XpoTutorials.exe).

See Also