A component that can be used as a data source for the GridControl and SearchLookUpEdit controls in Instant Feedback Mode.
XPInstantFeedbackSource类是可以给GridControl 和SearchLookUpEdit控件做数据源的一种即时回馈组件。
Namespace:DevExpress.Xpo
Assembly:DevExpress.Xpo.v12.2.dll
命名空间:DevExpress.Xpo,在程序集DevExrepss.Xpo.v12.2.dll
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 an IAsyncListServer instance via the IListSource.GetList method. The XPInstantFeedbackSource component implements the IListSource interface, and returns the list implementing the IAsyncListServer 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 bound XPInstantFeedbackSource 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 (an XPBaseObject 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 the XPInstantFeedbackSource 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.
Note |
---|
The XPInstantFeedbackSource is a read-only data source. To enable data editing in server mode, use the XPServerCollectionSource with the XPServerCollectionSource.AllowEdit property set to true. |
For additional information on Instant Feedback mode, refer to Instant Feedback Mode.
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 the PersistentAttribute attribute. Then, this class is used as a parameter in the XPInstantFeedbackSource 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简单来说就是:在页面你浏览了多少行,就只能操作多少行数据。