Interface ICollectionView
ICollectionView is an interface that applications writing their own collections can implement to enable current record management, sorting, filtering, grouping etc in a custom way.
Inherited Members
Namespace: System.ComponentModel
Assembly: OpenSilver.dll
Syntax
public interface ICollectionView : IEnumerable, INotifyCollectionChanged
Properties
| Improve this Doc View SourceCanFilter
Indicates whether or not this ICollectionView can do any filtering.
Declaration
bool CanFilter { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
CanGroup
Returns true if this view really supports grouping. When this returns false, the rest of the interface is ignored.
Declaration
bool CanGroup { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
CanSort
Whether or not this ICollectionView does any sorting.
Declaration
bool CanSort { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Culture
Culture contains the CultureInfo used in any operations of the ICollectionView that may differ by Culture, such as sorting.
Declaration
CultureInfo Culture { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Globalization.CultureInfo |
CurrentItem
Return current item.
Declaration
object CurrentItem { get; }
Property Value
| Type | Description |
|---|---|
| System.Object |
CurrentPosition
The ordinal position of the CurrentItem within the (optionally sorted and filtered) view.
Declaration
int CurrentPosition { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Filter
Filter is a callback set by the consumer of the ICollectionView and used by the implementation of the ICollectionView to determine if an item is suitable for inclusion in the view.
Declaration
Predicate<object> Filter { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Predicate<System.Object> |
GroupDescriptions
The description of grouping, indexed by level.
Declaration
ObservableCollection<GroupDescription> GroupDescriptions { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.ObjectModel.ObservableCollection<GroupDescription> |
Groups
The top-level groups, constructed according to the descriptions given in GroupDescriptions.
Declaration
ReadOnlyObservableCollection<object> Groups { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.ObjectModel.ReadOnlyObservableCollection<System.Object> |
IsCurrentAfterLast
Return true if CurrentItem is beyond the end (End-Of-File).
Declaration
bool IsCurrentAfterLast { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsCurrentBeforeFirst
Return true if CurrentItem is before the beginning (Beginning-Of-File).
Declaration
bool IsCurrentBeforeFirst { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsEmpty
Returns true if the resulting (filtered) view is emtpy.
Declaration
bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
SortDescriptions
Collection of Sort criteria to sort items in this view over the SourceCollection.
Declaration
SortDescriptionCollection SortDescriptions { get; }
Property Value
| Type | Description |
|---|---|
| SortDescriptionCollection |
Remarks
Simpler implementations do not support sorting and will return an empty and immutable / read-only SortDescription collection. Attempting to modify such a collection will cause NotSupportedException. Use CanSort property on CollectionView to test if sorting is supported before modifying the returned collection.
One or more sort criteria in form of SortDescription can be added, each specifying a property and direction to sort by.
SourceCollection
SourceCollection is the original un-filtered collection of which this ICollectionView is a view.
Declaration
IEnumerable SourceCollection { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.IEnumerable |
Methods
| Improve this Doc View SourceContains(Object)
Return true if the item belongs to this view. No assumptions are made about the item. This method will behave similarly to IList.Contains(). If the caller knows that the item belongs to the underlying collection, it is more efficient to call Filter.
Declaration
bool Contains(object item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | item |
Returns
| Type | Description |
|---|---|
| System.Boolean |
DeferRefresh()
Enter a Defer Cycle. Defer cycles are used to coalesce changes to the ICollectionView.
Declaration
IDisposable DeferRefresh()
Returns
| Type | Description |
|---|---|
| System.IDisposable |
MoveCurrentTo(Object)
Move CurrentItem to the given item.
Declaration
bool MoveCurrentTo(object item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | item | Move CurrentItem to this item. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if CurrentItem points to an item within the view. |
MoveCurrentToFirst()
Move CurrentItem to the first item.
Declaration
bool MoveCurrentToFirst()
Returns
| Type | Description |
|---|---|
| System.Boolean | true if CurrentItem points to an item within the view. |
MoveCurrentToLast()
Move CurrentItem to the last item.
Declaration
bool MoveCurrentToLast()
Returns
| Type | Description |
|---|---|
| System.Boolean | true if CurrentItem points to an item within the view. |
MoveCurrentToNext()
Move CurrentItem to the next item.
Declaration
bool MoveCurrentToNext()
Returns
| Type | Description |
|---|---|
| System.Boolean | true if CurrentItem points to an item within the view. |
MoveCurrentToPosition(Int32)
Move CurrentItem to the item at the given index.
Declaration
bool MoveCurrentToPosition(int position)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | position | Move CurrentItem to this index |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if CurrentItem points to an item within the view. |
MoveCurrentToPrevious()
Move CurrentItem to the previous item.
Declaration
bool MoveCurrentToPrevious()
Returns
| Type | Description |
|---|---|
| System.Boolean | true if CurrentItem points to an item within the view. |
Refresh()
Re-create the view, using any SortDescriptions.
Declaration
void Refresh()
Events
| Improve this Doc View SourceCurrentChanged
Raise this event after changing to a new current item.
Declaration
event EventHandler CurrentChanged
Event Type
| Type | Description |
|---|---|
| System.EventHandler |
CurrentChanging
Raise this event before change of current item pointer. Handlers can cancel the change.
Declaration
event CurrentChangingEventHandler CurrentChanging
Event Type
| Type | Description |
|---|---|
| CurrentChangingEventHandler |
Remarks
Classes implementing ICollectionView should use the following pattern:
Raise the CurrentChanging event before any change of currency and check the return value before proceeding and raising CurrentChanged event:
void MoveCurrentToNext()
{
CurrentChangingEventArgs args = new CurrentChangingEventArgs();
OnCurrentChanging(args);
if (!args.Cancel)
{
// ... update private data structures ...
CurrentChanged();
}
}