SortableBindingListT Class

Provides a sortable generic list that is able to notify its consumer about changes and supports data binding.

Definition

Namespace: KGySoft.ComponentModel
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.2.0
C#
[SerializableAttribute]
public class SortableBindingList<T> : FastBindingList<T>
Inheritance
Object    VirtualCollectionT    FastLookupCollectionT    FastBindingListT    SortableBindingListT

Type Parameters

T
The type of elements in the list.

Remarks

The SortableBindingListT class provides a sortable view for the wrapped list specified in the constructor.

To sort the list the ApplySort overloads can be used. As sorting is supported via the standard IBindingList interface, binding a SortableBindingListT instance to UI controls (eg. to a grid) enables sorting automatically in several GUI frameworks.

  Note

Sorting does not change the order of the elements in the wrapped underlying collection. When items are added while IsSorted returns , then new items are added to the end of the underlying list.

  Caution

Do not store elements in a SortableBindingListT that may change their hash code while they are added to the collection. Finding such elements may fail even if CheckConsistency is . If hash code is derived from some identifier property or field, you can prepare a T instance by overriding the AddNewCore method or by subscribing the AddingNew event to make IBindingList.AddNew implementation work properly.

Constructors

SortableBindingListT Initializes a new instance of the SortableBindingListT class with a CircularListT internally.
SortableBindingListT(IListT) Initializes a new instance of the SortableBindingListT class with the specified list.

Properties

AllowEdit Gets or sets whether item properties can be edited in the list.
Default value: .
(Inherited from FastBindingListT)
AllowNew Gets or sets whether new items can be added to the list by the AddNew method.
Default value: if the wrapped list is not read-only and T is a value type or has a parameterless constructor; otherwise, .
(Inherited from FastBindingListT)
AllowRemove Gets or sets whether items can be removed from the list by the Remove, RemoveAt and Clear methods.
Default value: if the wrapped list is not read-only; otherwise, .
(Inherited from FastBindingListT)
CanSetItem Gets whether an item can be set through the indexer.
The base implementation returns if IsReadOnly returns or when the wrapped collection is a one dimensional zero based array of T; otherwise, returns .
(Inherited from VirtualCollectionT)
CheckConsistency Gets or sets whether consistency of the stored items should be checked when items are get or set in the collection.
Default value: , if the FastLookupCollectionT was initialized by the default constructor; otherwise, as it was specified.
(Inherited from FastLookupCollectionT)
Count Gets the number of elements actually contained in the VirtualCollectionT.
The base implementation returns the Count property of the underlying collection.
(Inherited from VirtualCollectionT)
DisposeBehavior Specifies the strategy for treating the wrapped Items and the added values when this instance is disposed.
Default value: DisposeCollection.
(Inherited from FastBindingListT)
IsReadOnly Gets whether the VirtualCollectionT is read-only. Affects the behavior of Add, Insert, Remove, RemoveAt and Clear methods.
The base implementation returns the IsReadOnly property of the underlying collection.
(Inherited from VirtualCollectionT)
IsSorted Gets whether the items in the list are sorted.
(Inherited from FastBindingListT)
IsSortedCore Gets whether the list is sorted.
(Overrides FastBindingListTIsSortedCore)
Item Gets or sets the element at the specified index.
When read, calls the overridable GetItem method, and when set, calls the overridable SetItem method.
(Inherited from VirtualCollectionT)
Items Gets the wrapped underlying collection maintained by this VirtualCollectionT instance.
(Inherited from VirtualCollectionT)
PropertyDescriptors Gets the property descriptors of T.
(Inherited from FastBindingListT)
RaiseListChangedEvents Gets or sets whether adding or removing items within the list raises ListChanged events.
Default value: .
(Inherited from FastBindingListT)
SortDirection Gets or sets the direction of the sort. Returns , if the list is not sorted (that is, when IsSorted returns ). Setting removes sorting. To change also the SortProperty call the ApplySort(PropertyDescriptor, ListSortDirection) method instead.
SortDirectionCore Gets the direction of the sort.
If the list is not sorted (that is, when IsSorted returns ), this property returns Ascending.
(Overrides FastBindingListTSortDirectionCore)
SortOnChange Gets or sets whether the SortableBindingListT should be immediately re-sorted when an item changes or a new item is added.
Default value: .
SortProperty Gets a PropertyDescriptor that is being used for sorting. Returns if the list is not sorted or when it is sorted by the values of T rather than by one of its properties.
(Inherited from FastBindingListT)
SortPropertyCore Gets the property descriptor that is used for sorting the list if sorting, or if the list is not sorted or when it is sorted by the values of T rather than by one of its properties.
(Overrides FastBindingListTSortPropertyCore)
SupportsChangeNotificationCore Gets whether ListChanged events are enabled.
The base implementation returns .
(Inherited from FastBindingListT)
SupportsSearchingCore Gets whether the list supports searching.
The base implementation returns .
(Inherited from FastBindingListT)
SupportsSortingCore Gets whether the list supports sorting.
The SortableBindingListT returns .
(Overrides FastBindingListTSupportsSortingCore)

Methods

Add Adds an object to the end of the VirtualCollectionT.
Calls the overridable InsertItem method.
(Inherited from VirtualCollectionT)
AddIndexCore If overridden in a derived class, adds the PropertyDescriptors to the indices used for searching.
The base implementation does nothing.
(Inherited from FastBindingListT)
AddNew Adds a new item to the collection.
(Inherited from FastBindingListT)
AddNewCore Adds a new item to the collection.
(Inherited from FastBindingListT)
ApplySort(ListSortDirection) Sorts the list by the values of T rather than one of its properties based on the specified direction.
(Inherited from FastBindingListT)
ApplySort(PropertyDescriptor, ListSortDirection) Sorts the list based on the specified property and direction.
(Inherited from FastBindingListT)
ApplySort(String, ListSortDirection) Sorts the list based on the specified propertyName and direction.
(Inherited from FastBindingListT)
ApplySortCore Sorts the items of the list.
(Overrides FastBindingListTApplySortCore(PropertyDescriptor, ListSortDirection))
CancelNew Discards a pending new item added by the AddNew method.
(Overrides FastBindingListTCancelNew(Int32))
Clear Removes all elements from the VirtualCollectionT.
Calls the overridable ClearItems method.
(Inherited from VirtualCollectionT)
ClearItems Removes all elements from the SortableBindingListT.
(Overrides FastBindingListTClearItems)
Contains Determines whether an element is in the VirtualCollectionT.
Calls the overridable ContainsItem method.
(Inherited from VirtualCollectionT)
ContainsItem Gets whether the specified item is in the VirtualCollectionT.
The base implementation calls the GetItemIndex method.
(Inherited from VirtualCollectionT)
CopyTo Copies the entire VirtualCollectionT to a compatible one-dimensional Array, starting at the specified arrayIndex of the target array.
Calls the overridable GetItem method for each index between zero and Count, excluding upper bound.
(Inherited from VirtualCollectionT)
Dispose Releases the list and removes both incoming and outgoing subscriptions.
(Inherited from FastBindingListT)
Dispose(Boolean) Releases the resources used by this FastBindingListT instance.
(Inherited from FastBindingListT)
EndNew Commits a pending new item of any position added by the AddNew method.
(Overrides FastBindingListTEndNew)
EndNew(Int32) Commits a pending new item added by the AddNew method.
(Overrides FastBindingListTEndNew(Int32))
Find(PropertyDescriptor, Object) Searches for the index of the item that has the specified property descriptor with the specified value.
(Inherited from FastBindingListT)
Find(String, Object) Searches for the index of the item that has the specified property descriptor with the specified value.
(Inherited from FastBindingListT)
FindCore Searches for the index of the item that has the specified property descriptor with the specified value.
(Overrides FastBindingListTFindCore(PropertyDescriptor, Object))
GetEnumerator Returns an enumerator that iterates through the SortableBindingListT.
(Overrides VirtualCollectionTGetEnumerator)
GetItem Gets the element at the specified index.
(Overrides FastBindingListTGetItem(Int32))
GetItemIndex Gets the zero-based index of the first of the specified item within the FastLookupCollectionT.
(Overrides FastLookupCollectionTGetItemIndex(T))
IndexOf Searches for the specified object and returns the zero-based index of an occurrence within the entire VirtualCollectionT.
Calls the overridable GetItemIndex method.
(Inherited from VirtualCollectionT)
InnerListChanged Invalidates the internally stored index mapping. Call if the wrapped list that has been passed to the constructor has been changed explicitly.
(Overrides FastLookupCollectionTInnerListChanged)
Insert Inserts an element into the VirtualCollectionT at the specified index.
Calls the overridable InsertItem method.
(Inherited from VirtualCollectionT)
InsertItem Inserts an element into the SortableBindingListT at the specified index.
(Overrides FastBindingListTInsertItem(Int32, T))
OnAddingNew Raises the AddingNew event.
(Inherited from FastBindingListT)
OnListChanged Raises the ListChanged event.
(Overrides FastBindingListTOnListChanged(ListChangedEventArgs))
OnMapRebuilt Called after the internal index map has been rebuilt either when inconsistency has been detected or when InnerListChanged has been called.
(Inherited from FastBindingListT)
Remove Removes one occurrence of a specific object from the VirtualCollectionT.
Calls the overridable RemoveItem method.
(Inherited from VirtualCollectionT)
RemoveAt Removes the element at the specified index of the VirtualCollectionT.
Calls the overridable RemoveItem method.
(Inherited from VirtualCollectionT)
RemoveIndexCore If overridden in a derived class, removes the PropertyDescriptors from the indices used for searching.
The base implementation does nothing.
(Inherited from FastBindingListT)
RemoveItem Removes the first occurrence of item from the SortableBindingListT.
(Overrides FastLookupCollectionTRemoveItem(T))
RemoveItemAt Removes the element at the specified index from the SortableBindingListT.
(Overrides FastBindingListTRemoveItemAt(Int32))
RemoveSort Removes any sort applied by the ApplySort overloads.
(Inherited from FastBindingListT)
RemoveSortCore Removes any sort applied by the ApplySortCore method.
(Overrides FastBindingListTRemoveSortCore)
ResetBindings Raises the ListChanged event of type Reset.
(Inherited from FastBindingListT)
ResetItem Raises the ListChanged event of type ItemChanged at the specified position.
(Inherited from FastBindingListT)
SetItem Replaces the item at the specified index.
(Overrides FastBindingListTSetItem(Int32, T))

Events

AddingNew Occurs when a new item is added to the list by the AddNew method.
(Inherited from FastBindingListT)
ListChanged Occurs when the list or an item in the list changes.
(Inherited from FastBindingListT)

Extension Methods

Convert Converts an Object specified in the obj parameter to the desired targetType.
See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example.
(Defined by ObjectExtensions)
ConvertTTarget Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions)
In Gets whether item is among the elements of set.
See the Examples section of the generic InT(T, T) overload for an example.
(Defined by ObjectExtensions)
TryConvert Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvert Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvertTTarget Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvertTTarget Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)

See Also