The Collection Source used by default for the List Views that display collections of business objects.
The CollectionSource is used by the root (see View.IsRoot) List Views. Generally, you can expect a List View to use the CollectionSource in the following cases:
A List View that is displayed in the XAF main window. In this case, the List View uses an instance of the CollectionSource class as its Collection Source.
A nested List View that displays a collection property uses the PropertyCollectionSource as the data source. However, the List View displayed in a pop-up Window invoked via the LinkUnlinkController.LinkAction uses the CollectionSource, in case the collection property does not have the DataSourcePropertyAttribute applied.
To display a drop-down list of the possible values for a reference property, a Lookup Property Editor creates a List View. This List View uses an instance of the CollectionSource class as a data source, if the DataSourcePropertyAttribute is not applied to the reference property.
If the reference property has the DataSourceProperty attribute applied, the LookupEditPropertyCollectionSource is used instead.
By default, a CollectionSource instance is created in Client mode. But you can set a DataView, Server, ServerView, InstantFeedback, or InstantFeedbackView mode (see CollectionSourceBase.DataAccessMode) using the Application Model. In the Model Editor, navigate to the List View node representing the target View and set the IModelListView.DataAccessMode property to one of the CollectionSourceDataAccessMode enumeration values.
If you want to create a Collection Source for a nested List View in Server, ServerView, InstantFeedback, or InstantFeedbackView mode, make sure that there is no logic for sorting, filtering or something else in the collection's getter, and there are no subscribers to the collection's events. This logic and subscribers won't be taken into account, because a standalone server collection will be created instead of the original one.
XAF automatically creates and manipulates a Collection Source when it creates a List View. However, there are few typical tasks that require you to instantiate or access a Collection Source manually. Here they are:
- Create a custom List View. To be able to do it, you need to first create the required collection source.
- Filter a collection of objects that a List View displays on the data source level. To do this, you need to access the List View's Collection Source (see Criteria Property of a List View's Collection Source).