XPInstantFeedbackSource Class

来源:互联网 发布:数据预处理步骤 编辑:程序博客网 时间:2024/06/16 01:23

A component that can be used as a data source for the GridControl and SearchLookUpEdit controls inInstant Feedback Mode.

XPInstantFeedbackSource类是可以给GridControl 和SearchLookUpEdit控件做数据源的一种即时回馈组件。

Namespace:DevExpress.Xpo
Assembly:DevExpress.Xpo.v12.2.dll

命名空间:DevExpress.Xpo,在程序集DevExrepss.Xpo.v12.2.dll

Remarks
Instant Feedback binding mode is an improvement over the regularserver mode. In server mode, the XtraGrid loads data in small portions and delegates all data operations (sorting, grouping, filtering and calculating summaries) to the data server. This is the key to the server mode's high efficiency when working with large volumes of data. The only drawback to using server mode involves data operations when the connection to the server is slow. In this instance, the bound control freezes until the data server completes operations and retrieves results. With Instant Feedback binding mode, data operations are performed asynchronously in a background thread, and both the bound control and the application remain highly responsive. Currently, this mode is supported by theDevExpress.XtraGrid.GridControl and DevExpress.XtraEditors.SearchLookUpEdit controls.

A data source supporting Instant Feedback mode must either implement the DevExpress.Data.Async.IAsyncListServer interface or implement the System.ComponentModel.IListSource interface and return anIAsyncListServer instance via the IListSource.GetList method. TheXPInstantFeedbackSource component implements the IListSource interface, and returns the list implementing theIAsyncListServer interface via the IListSource.GetList method.

The XPInstantFeedbackSource object serves as a conduit of information between the control and a target data store. When the control needs to display a specific portion of data, it calls a specific method of the boundXPInstantFeedbackSource object. This method sends a corresponding request to the data store, and while receiving the results, immediately passes them back to the control.

When creating an XPInstantFeedbackSource object, you need to provide descriptive information on the target data table (view) in the target data store. Declare a persistent class (anXPBaseObject descendant) that will correspond to the data table (see Basics of Creating Persistent Objects for Existing Data Tables). Then, pass the persistent class type to theXPInstantFeedbackSource constructor. You can use the ObjectType property, to choose the required persistent class at design time. In Instant Feedback mode, the target data table must contain a single key field, and the persistent class must contain a public property corresponding to the table key. If the data table does not contain a key field or the key is composed of several columns, it cannot be used as a data source.

NoteNote

The XPInstantFeedbackSource is a read-only data source. To enable data editing in server mode, use theXPServerCollectionSource with the XPServerCollectionSource.AllowEdit property set to true.
The XPInstantFeedbackSource can only work with thread-safe properties. Reference properties are not thread safe. So, you should not use reference property descriptors when specifyingDisplayableProperties.
Assign the DefaultSorting, DisplayableProperties, FixedFilterCriteria, FixedFilterString, and ObjectType properties before binding the XPInstantFeedbackSource to the GridControl or SearchLookUpEdit. Once bound, changing any of these properties throws an exception.

For additional information on Instant Feedback mode, refer to Instant Feedback Mode.

Examples

This example demonstrates how to initialize a XPInstantFeedbackSource, to retrieve data from a "Person.Contact" data table (included in the AdventureWorks database shipped with MS SQL Server). The Person_Contact persistent class is declared, and mapped to the "Person.Contact" data table, using thePersistentAttribute attribute. Then, this class is used as a parameter in theXPInstantFeedbackSource constructor.

using DevExpress.Xpo;using DevExpress.Xpo.DB;using DevExpress.Data.Filtering;// The persistent class describing the "Person.Contact" table // from the AdventureWorks SQL database[Persistent("Person.Contact")]public class Person_Contact : XPLiteObject {            [Key]    public System.Int32 ContactID;    public string FirstName;    public string LastName;    //...}public partial class Form1 : Form {    //...    public Form1() {        // ...        // Create a filter that selects records where last names start with 'A'             CriteriaOperator criteria = CriteriaOperator.Parse("[LastName] LIKE ?", "A%");        // Specify the properties that will be available for binding        string displayableProperties = "FirstName;LastName";            // Initialize an XPInstantFeedbackSource data source         // supplying data from the Person.Contact data table             XPInstantFeedbackSource instantDS = new XPInstantFeedbackSource(            typeof(Person_Contact), displayableProperties, criteria);        // Handle the ResolveSession event,         // to provide a Session to the XPInstantFeedbackSource        instantDS.ResolveSession += instantDS_ResolveSession;        // Handle the DismissSession event, to dispose of the Session        instantDS.DismissSession += instantDS_DismissSession;        //...    }    void instantDS_ResolveSession(object sender, ResolveSessionEventArgs e) {        Session session = new Session();        session.ConnectionString = @"Integrated Security=SSPI;Pooling=false;            Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase";        session.Connect();        e.Session = session;    }    void instantDS_DismissSession(object sender, ResolveSessionEventArgs e) {        IDisposable session = e.Session as IDisposable;        if(session != null) {            session.Dispose();        }    }}


 

XPInstantFeedbackSource 类,对gridview简单来说就是:在页面你浏览了多少行,就只能操作多少行数据。