Back to Devexpress

XPView Class

xpo-devexpress-dot-xpo-e9bb9711.md

latest9.5 KB
Original Source

XPView Class

The view that stores data retrieved from persistent objects.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

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

The following members return XPView objects:

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.

csharp
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);
vb
Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
' ...
Private Sub InitViewColumns(ByVal view As XPView)
        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)})
End Sub
' ...
Dim _xpView As XPView = New XPView(Session.DefaultSession, GetType(WinApplication.Cars))
InitViewColumns(_xpView)

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

csharp
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)});
vb
Imports 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.

csharp
xpView.Criteria = CriteriaOperator.Parse("[Price] < 100000", null);
gridControl1.DataSource = xpView;
vb
_xpView.Criteria = CriteriaOperator.Parse("[Price] < 100000", Nothing)
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 25.2\Components\WinForms\Bin\XpoTutorials.exe).

Member Table

MemberDescription
XPView.CriteriaSpecifies the criteria by which the data store will be filtered while the view is being loaded.
XPView.GroupCriteriaSpecifies the view’s grouping criteria.
XPView.ObjectClassInfoGets or sets the metadata information that describes the type of objects displayed by a view.
XPView.SessionThe session which is used to load and save persistent objects
XPView.SortingProvides access to the collection whose elements identify the sorted columns within the view.
XPView.PropertiesProvides access to the view’s column collection.
ViewPropertyRepresents a column within the view.
ViewRecordRepresents a record within the view.

Implements

ISessionProvider

Inheritance

Object MarshalByRefObject Component XPView

See Also

XPView Members

XPView

DevExpress.Xpo Namespace