Skip to main content
.NET 6.0+

XPDataView Class

The data source that displays data from result sets.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v23.2.dll

NuGet Package: DevExpress.Xpo

Declaration

public class XPDataView :
    Component,
    ISupportInitialize,
    IBindingList,
    ICollection,
    IEnumerable,
    IList,
    ITypedList,
    IFilteredXtraBindingList,
    IFilteredDataSource,
    IXPDictionaryProvider
public class XPDataView :
    Component,
    ISupportInitialize,
    IBindingList,
    IList,
    ICollection,
    IEnumerable,
    ITypedList,
    IFilteredXtraBindingList,
    IFilteredDataSource,
    IXPDictionaryProvider

Remarks

Like an XPView, the XPDataView is intended only to display data from result sets, which can be obtained from a data store using direct SQL queries and stored procedures. The main difference from the XPCollection, XPCursor, and XPView, is that the XPDataView is session-less - no Session is required to retrieve data from a data store, as it is already been retrieved into a result set.

The data view’s columns are stored in the XPDataView.Properties collection. When a new instance of the XPDataView class is created, this collection is empty. So, you should manually populate it and then load the result set data into the data view.

An XPDataView 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 XPDataView

At design time, you can create an XPDataView by dragging the corresponding item from the DX.23.2: ORM Components tab of the Toolbox onto your form or component. Then, you can manually populate the data view with columns via the XPDataView.Properties collection’s built-in editor, allowing you to add/remove columns and specify their names and types. Result set contents can then be loaded into the data view in code, using the XPDataView.LoadData or XPDataView.LoadOrderedData method, as shown below.

using DevExpress.Xpo;
using DevExpress.Xpo.DB;

// ...
// For brevity, we omitted the code initializing session1 (a session 
// that is used to retrieve data from a data store into a result set).
SelectedData resultSet = session1.ExecuteQuery("SELECT Name, Age FROM [Person]");

// We assume that the Name and Age columns are created and stored in this
// exact order within the xpDataView1.Properties collection. So, there is
// no need to call LoadOrderedData and use column mapping information.
xpDataView1.LoadData(resultSet);

At runtime, you can create an XPDataView using overloaded constructors, which, in addition to creating the data view, allow you to populate it with columns and load result set data into it, in one step. Alternatively, you can create an XPDataView with certain settings, and later, populate it with required columns (via XPDataView.AddProperty, DataViewPropertiesCollection.Add, XPDataView.PopulateProperties and XPDataView.PopulatePropertiesOrdered) and load the result set data (via XPDataView.LoadData or XPDataView.LoadOrderedData).

The following example demonstrates how to create a new XPDataView, populate its XPDataView.Properties collection with columns and load data.

using DevExpress.Xpo;
using DevExpress.Xpo.DB;

// ...
SelectedData resultSet = session1.ExecuteQuery("SELECT Name, Age FROM [Person]");
XPDataView xpDataView1 = new XPDataView(session1.Dictionary, session1.GetClassInfo<Person>(), 
    new string[] { "Name", "Age" });
xpDataView1.LoadData(resultSet);

The code examples above assume that XPDataView columns are stored in the XPDataView.Properties collection in the exact order as corresponding result set columns. If the order is different or a result set contains columns that you do not want to display, call the XPDataView.LoadOrderedData method and use column mapping information. To learn how to load result set data using mapping information, refer to this method’s description.

Filtering an XPDataView

The XPDataView allows its records to be filtered on the client. To apply filter criteria use the XPDataView.Filter or XPDataView.FilterString property. For more information on filtering, refer to topics in the Filtering section.

In the following example, the data view contents are filtered to display people between the ages of 30 and 50 (inclusive).

xpDataView1.FilterString = "Age Between (30, 50)";

Sorting Data in an XPDataView

You can sort XPDataView contents by column values on the client. To accomplish this, use the XPDataView.Sorting property. For more information on sorting, refer to topics in the Sorting section.

The code sample below shows how to sort XPDataView by descending age and then, by the ascending order of names.

SortingCollection sortCollection = new SortingCollection();
sortCollection.Add(new SortProperty("Age", SortingDirection.Descending));
sortCollection.Add(new SortProperty("Name", SortingDirection.Ascending));
xpDataView1.Sorting = sortCollection;

Member Table

Member Description
XPDataView.Filter Specifies the criteria used to perform client-side filtering of data view rows.
XPDataView.FilterString Specifies the string representation of the criteria used to perform client-side filtering of data view rows.
XPDataView.LoadData Loads data from the specified result set to the data view.
XPDataView.LoadOrderedData Loads data from the specified result set to the data view, mapping data view columns to result set columns.
XPDataView.PopulateProperties Populates the data view with columns based on the specified metadata information.
XPDataView.PopulatePropertiesOrdered Populates the data view with columns based on the specified metadata and mapping information.
XPDataView.Properties Provides access to the data view’s columns.
XPDataView.Sorting Provides access to the collection whose elements identify the sorted columns within the view.
DataViewProperty Represents a column within the data view.
DataViewRecord Represents a record within the data view.

Inheritance

See Also