CollectionSourceBase.Mode Property
Indicates the Collection Source’s mode of operation.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Property Value
Type | Description |
---|---|
CollectionSourceMode | A CollectionSourceMode enumeration value specifying the Collection Source’s mode of operation. |
Remarks
The Mode property indicates the mode in which the current Collection Source is created. The following modes are possible:
Normal
A collection of objects of the specified type is created by the CollectionSourceBase.ObjectSpace. For instance, the XPObjectSpace creates an XPCollection. All operations, e.g. filtering, are applied to it. This collection is accessible using the CollectionSourceBase.Collection property.
Proxy
Two collections are created. The first one is an original collection created by the Object Space. The second one is an intermediate proxy collection. It represents the original collection’s wrapper, because it implements several interfaces that are required for different built-in features. The CollectionSourceBase.Collection property returns the proxy collection.
Suppose you have filtered a List View via the ListViewFilterAttribute. In Normal mode, if you iterate over the collection represented by the List View, you will only see the filtered objects. This is because in this mode, when the Collection Source’s collection is filtered, the corresponding criteria is directly applied to the collection. In Proxy mode, the criteria are not directly applied to the original object collection. Instead, the filter criteria are applied to the proxy collection. So, in this mode, the underlying collection is unaffected and if you iterate over it, you will see all objects belonging to the collection.
To access the original collection of the Collection Source that is created in the Proxy mode, use the following code:
private PropertyCollectionSource propertyCollectionSource;
//...
propertyCollectionSource = ((ListView)View).CollectionSource as PropertyCollectionSource;
if (propertyCollectionSource != null) {
propertyCollectionSource.CollectionChanged +=
new EventHandler(propertyCollectionSource_CollectionChanged);
}
//...
void propertyCollectionSource_CollectionChanged(object sender, EventArgs e) {
XPBaseCollection collection = propertyCollectionSource.MemberInfo.GetValue(
propertyCollectionSource.MasterObject) as XPBaseCollection;
//Access the collection object here.
}
The Mode property does not affect control-specific filtering features. For instance, the GridControl used by the GridListEditor, allows end-users to filter data via the auto filter row and filter panel. When end-users use these features, filtering is performed on the control level and is not reflected in the Collection Source.
Note
When a Collection Source is created in a mode other than Client (see CollectionSourceBase.DataAccessMode), the Mode property is automatically set to Normal, because a proxy collection cannot be used.
When a Collection Source is created, the Mode property is set to Proxy, by default. However, you can apply the CollectionSourceModeAttribute to an individual collection property to indicate which mode is required for the Collection Source that will be created for the nested List View representing the collection. Additionally, when you have to create a Collection Source in code, you can use a constructor with the mode parameter.