Export (0) Print
Expand All

ListCollectionView Class

Represents the collection view for collections that implement IList.

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)

public class ListCollectionView : CollectionView, 
	IComparer, IEditableCollectionViewAddNewItem, IEditableCollectionView, ICollectionViewLiveShaping, IItemProperties

The ListCollectionView type exposes the following members.

  NameDescription
Public methodListCollectionViewInitializes a new instance of the ListCollectionView class, using a supplied collection that implements IList.
Top

  NameDescription
Protected propertyActiveComparerGets or sets the current active comparer that is used in sorting.
Protected propertyActiveFilterGets or sets the current active Filter callback.
Protected propertyAllowsCrossThreadChangesGets a value that indicates whether a thread other than the one that created the CollectionView can change the SourceCollection. (Inherited from CollectionView.)
Public propertyCanAddNewGets a value that indicates whether a new item can be added to the collection.
Public propertyCanAddNewItemGets a value that indicates whether a specified object can be added to the collection.
Public propertyCanCancelEditGets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object.
Public propertyCanChangeLiveFilteringGets a value that indicates whether the collection view supports turning filtering data in real time on or off.
Public propertyCanChangeLiveGroupingGets a value that indicates whether the collection view supports turning grouping data in real time on or off.
Public propertyCanChangeLiveSortingGets a value that indicates whether the collection view supports turning sorting data in real time on or off.
Public propertyCanFilterGets a value that indicates whether the view supports callback-based filtering. (Overrides CollectionView.CanFilter.)
Public propertyCanGroupGets a value that indicates whether the collection view supports grouping. (Overrides CollectionView.CanGroup.)
Public propertyCanRemoveGets a value that indicates whether an item can be removed from the collection.
Public propertyCanSortGets a value that indicates whether the collection view supports sorting. (Overrides CollectionView.CanSort.)
Public propertyComparerReturns an object that you can use to compare items in the view. (Inherited from CollectionView.)
Public propertyCountGets the estimated number of records. (Overrides CollectionView.Count.)
Public propertyCultureGets or sets the culture information to use during sorting. (Inherited from CollectionView.)
Public propertyCurrentAddItemGets the item that is being added during the current add transaction.
Public propertyCurrentEditItemGets the item in the collection that is being edited.
Public propertyCurrentItemGets the current item in the view. (Inherited from CollectionView.)
Public propertyCurrentPositionGets the ordinal position of the CurrentItem within the (optionally sorted and filtered) view. (Inherited from CollectionView.)
Public propertyCustomSortGets or sets a custom object that implements IComparer to sort items in the view.
Public propertyDispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public propertyFilterGets or sets a method that is used to determine whether an item is suitable for inclusion in the view. (Overrides CollectionView.Filter.)
Public propertyGroupBySelectorGets or sets a delegate to select the GroupDescription as a function of the parent group and its level.
Public propertyGroupDescriptionsGets a collection of GroupDescription objects that describe how the items in the collection are grouped in the view. (Overrides CollectionView.GroupDescriptions.)
Public propertyGroupsGets the top-level groups. (Overrides CollectionView.Groups.)
Protected propertyInternalCountGets the number of records in the InternalList.
Protected propertyInternalListGets the complete and unfiltered underlying collection.
Public propertyIsAddingNewGets a value that indicates whether an add transaction is in progress.
Public propertyIsCurrentAfterLastGets a value that indicates whether the CurrentItem of the view is beyond the end of the collection. (Inherited from CollectionView.)
Public propertyIsCurrentBeforeFirstGets a value that indicates whether the CurrentItem of the view is before the beginning of the collection. (Inherited from CollectionView.)
Protected propertyIsCurrentInSyncGets a value that indicates whether the CurrentItem is at the CurrentPosition. (Inherited from CollectionView.)
Public propertyIsDataInGroupOrderGets or sets a value that indicates whether the list of items (after applying the sort and filters, if any) is already in the correct order for grouping.
Protected propertyIsDynamicGets a value that indicates whether the underlying collection provides change notifications. (Inherited from CollectionView.)
Public propertyIsEditingItemGets a value that indicates whether an edit transaction is in progress.
Public propertyIsEmptyReturns a value that indicates whether the resulting (filtered) view is empty. (Overrides CollectionView.IsEmpty.)
Protected propertyIsGroupingGets a value that indicates whether there are groups in the view.
Public propertyIsInUseGets a value that indicates whether any object is subscribing to the events of this CollectionView. (Inherited from CollectionView.)
Public propertyIsLiveFilteringGets or sets a value that indicates whether filtering data in real time is enabled.
Public propertyIsLiveGroupingGets or sets a value that indicates whether grouping data in real time is enabled.
Public propertyIsLiveSortingGets or sets a value that indicates whether sorting in real time is enabled.
Protected propertyIsRefreshDeferredGets a value that indicates whether there is an outstanding DeferRefresh in use. (Inherited from CollectionView.)
Public propertyItemPropertiesGets a collection of objects that describes the properties of the items in the collection.
Public propertyLiveFilteringPropertiesGets a collection of strings that specify the properties that participate in filtering data in real time.
Public propertyLiveGroupingPropertiesGets a collection of strings that specify the properties that participate in grouping data in real time.
Public propertyLiveSortingPropertiesGets a collection of strings that specify the properties that participate in sorting data in real time.
Public propertyNeedsRefreshGets a value that indicates whether the view needs to be refreshed. (Inherited from CollectionView.)
Public propertyNewItemPlaceholderPositionGets or sets the position of the new item placeholder in the ListCollectionView.
Public propertySortDescriptionsGets a collection of SortDescription objects that describes how the items in the collection are sorted in the view. (Overrides CollectionView.SortDescriptions.)
Public propertySourceCollectionReturns the underlying unfiltered collection. (Inherited from CollectionView.)
Protected propertyUpdatedOutsideDispatcherGets a value that indicates whether it has been necessary to update the change log because a CollectionChanged notification has been received on a different thread without first entering the user interface (UI) thread dispatcher. (Inherited from CollectionView.)
Protected propertyUsesLocalArrayGets a value that indicates whether a private copy of the data is needed for sorting and filtering.
Top

  NameDescription
Public methodAddNewStarts an add transaction and returns the pending new item.
Public methodAddNewItemAdds the specified object to the collection.
Public methodCancelEditEnds the edit transaction, and if possible, restores the original value to the item.
Public methodCancelNewEnds the add transaction and discards the pending new item.
Public methodCheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Protected methodClearChangeLog Obsolete. Clears any pending changes from the change log. (Inherited from CollectionView.)
Protected methodClearPendingChangesClears unprocessed changed to the collection. (Inherited from CollectionView.)
Public methodCommitEditEnds the edit transaction and saves the pending changes.
Public methodCommitNewEnds the add transaction and saves the pending new item.
Protected methodCompareCompares two objects and returns a value that indicates whether one is less than, equal to, or greater than the other.
Public methodContainsReturns a value that indicates whether a given item belongs to the collection view. (Overrides CollectionView.Contains(Object).)
Public methodDeferRefreshEnters a defer cycle that you can use to merge changes to the view and delay automatic refresh. (Inherited from CollectionView.)
Public methodDetachFromSourceCollectionRemoves the reference to the underlying collection from the CollectionView. (Inherited from CollectionView.)
Public methodEditItemBegins an edit transaction of the specified item.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected methodGetEnumeratorReturns an object that you can use to enumerate the items in the view. (Overrides CollectionView.GetEnumerator().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetItemAtRetrieves the item at the specified position in the view. (Overrides CollectionView.GetItemAt(Int32).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfReturns the index where the given data item belongs in the collection, or -1 if the index of that item is unknown. (Overrides CollectionView.IndexOf(Object).)
Protected methodInternalContainsReturn a value that indicates whether the InternalList contains the item.
Protected methodInternalGetEnumeratorReturns an enumerator for the InternalList.
Protected methodInternalIndexOfReturns the index of the specified item in the InternalList.
Protected methodInternalItemAtReturns the item at the given index in the InternalList.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodMoveCurrentToSets the specified item to be the CurrentItem in the view. (Inherited from CollectionView.)
Public methodMoveCurrentToFirstSets the first item in the view as the CurrentItem. (Inherited from CollectionView.)
Public methodMoveCurrentToLastSets the last item in the view as the CurrentItem. (Inherited from CollectionView.)
Public methodMoveCurrentToNextSets the item after the CurrentItem in the view as the CurrentItem. (Inherited from CollectionView.)
Public methodMoveCurrentToPositionSets the item at the specified index to be the CurrentItem in the view. (Overrides CollectionView.MoveCurrentToPosition(Int32).)
Public methodMoveCurrentToPreviousSets the item before the CurrentItem in the view as the CurrentItem. (Inherited from CollectionView.)
Protected methodOKToChangeCurrentReturns a value that indicates whether the view can change which item is the CurrentItem. (Inherited from CollectionView.)
Protected methodOnAllowsCrossThreadChangesChangedOccurs when the AllowsCrossThreadChanges property changes. (Overrides CollectionView.OnAllowsCrossThreadChangesChanged().)
Protected methodOnBeginChangeLogging Obsolete. Called by the base class to notify the derived class that a CollectionChanged event has been posted to the message queue. (Overrides CollectionView.OnBeginChangeLogging(NotifyCollectionChangedEventArgs).)
Protected methodOnCollectionChanged(NotifyCollectionChangedEventArgs)Raises the CollectionChanged event. (Inherited from CollectionView.)
Protected methodOnCollectionChanged(Object, NotifyCollectionChangedEventArgs)Raises the CollectionChanged event. (Inherited from CollectionView.)
Protected methodOnCurrentChangedRaises the CurrentChanged event. (Inherited from CollectionView.)
Protected methodOnCurrentChanging()Raises a CurrentChanging event that is not cancelable. (Inherited from CollectionView.)
Protected methodOnCurrentChanging(CurrentChangingEventArgs)Raises the CurrentChanging event with the specified arguments. (Inherited from CollectionView.)
Protected methodOnPropertyChangedRaises the PropertyChanged event using the specified arguments. (Inherited from CollectionView.)
Public methodPassesFilterReturns a value that indicates whether the specified item in the underlying collection belongs to the view. (Overrides CollectionView.PassesFilter(Object).)
Protected methodProcessCollectionChangedHandles CollectionChanged events. (Overrides CollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs).)
Protected methodProcessPendingChangesEnsures that all pending changes to the collection have been committed. (Inherited from CollectionView.)
Public methodRefreshRe-creates the view. (Inherited from CollectionView.)
Protected methodRefreshOrDeferRefreshes the view or specifies that the view needs to be refreshed when the defer cycle completes. (Inherited from CollectionView.)
Protected methodRefreshOverrideRecreates the view. (Overrides CollectionView.RefreshOverride().)
Public methodRemoveRemoves the specified item from the collection.
Public methodRemoveAtRemoves the item at the specified position from the collection.
Protected methodSetCurrent(Object, Int32)Sets the specified item and index as the values of the CurrentItem and CurrentPosition properties. (Inherited from CollectionView.)
Protected methodSetCurrent(Object, Int32, Int32)Sets the specified item and index as the values of the CurrentItem and CurrentPosition properties. This method can be called from a constructor of a derived class. (Inherited from CollectionView.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodVerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Top

  NameDescription
Protected eventCollectionChangedOccurs when the view has changed. (Inherited from CollectionView.)
Public eventCurrentChangedOccurs after the CurrentItem has changed. (Inherited from CollectionView.)
Public eventCurrentChangingOccurs when the CurrentItem is changing. (Inherited from CollectionView.)
Protected eventPropertyChangedOccurs when a property value has changed. (Inherited from CollectionView.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIComparer.CompareThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an IEnumerator object that you can use to enumerate the items in the view. (Inherited from CollectionView.)
Explicit interface implemetationPrivate eventINotifyCollectionChanged.CollectionChangedOccurs when the view has changed. (Inherited from CollectionView.)
Explicit interface implemetationPrivate eventINotifyPropertyChanged.PropertyChangedOccurs when a property value changes. (Inherited from CollectionView.)
Top

When you bind to a data collection, you may want to sort, filter, or group the data. To do that, you use collection views. You can think of a CollectionView as the layer on top of the binding source collection that allows you to navigate and display the source collection based on sort, filter, and group queries, all without having to manipulate the underlying source collection itself. If the source collection implements the INotifyCollectionChanged interface, the changes raised by the CollectionChanged event are propagated to the views.

All collections have a default CollectionView. For all collections implementing IList, the ListCollectionView object is the default view object. The BindingListCollectionView is the collection view class used for collections that implement IBindingList. To get the default view, you use the GetDefaultView method. For an example, see How to: Get the Default View of a Data Collection.

For more information about collection views, see Data Binding Overview.

This example describes how to sort data in a view.

The following example creates a simple ListBox and a Button:

<Window x:Class="ListBoxSort_snip.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ListBoxSort_snip" Height="300" Width="300">
    <DockPanel>
      <ListBox Name="myListBox" DockPanel.Dock="Top">
        <ListBoxItem>my</ListBoxItem>
        <!--Or you can set the content this way:-->
        <!--<ListBoxItem Content="my"/>-->
        <ListBoxItem>1</ListBoxItem>
        <ListBoxItem>Sort</ListBoxItem>
        <ListBoxItem>3</ListBoxItem>
        <ListBoxItem>ListBox</ListBoxItem>
        <ListBoxItem>2</ListBoxItem>
      </ListBox>
      <Button Click="OnClick" Width="30" Height="20" DockPanel.Dock="Top">Sort</Button>
    </DockPanel>
</Window>

The Click event handler of the button contains logic to sort the items in the ListBox in the descending order. You can do this because adding items to a ListBox this way adds them to the ItemCollection of the ListBox, and ItemCollection derives from the CollectionView class. If you are binding your ListBox to a collection using the ItemsSource property, you can use the same technique to sort.

private void OnClick(object sender, RoutedEventArgs e)
{
    myListBox.Items.SortDescriptions.Add(
        new SortDescription("Content", ListSortDirection.Descending));
}

As long as you have a reference to the view object, you can use the same technique to sort the content of other collection views. For an example of how to obtain a view, see How to: Get the Default View of a Data Collection. For another example, see How to: Sort a GridView Column When a Header Is Clicked. For more information about views, see Binding to Collections in Data Binding Overview.

For an example of how to apply sorting logic in Extensible Application Markup Language (XAML), see How to: Sort and Group Data Using a View in XAML.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft