ObservableBindingListT Class

Provides a class that combines the features of an ObservableCollectionT and BindingListT. Unlike ObservableCollectionT, can raise the CollectionChanged event also when a property of a contained element changes.

Definition

Namespace: KGySoft.ComponentModel
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.0.0-rc.1
C#
[SerializableAttribute]
public class ObservableBindingList<T> : Collection<T>, 
	IDisposable, INotifyCollectionChanged, INotifyPropertyChanged, IBindingList, ICollection, 
	IEnumerable, IList, ICancelAddNew, IRaiseItemChangedEvents
Inheritance
Object    CollectionT    ObservableBindingListT
Implements
ICollection, IEnumerable, IList, INotifyCollectionChanged, IBindingList, ICancelAddNew, INotifyPropertyChanged, IRaiseItemChangedEvents, IDisposable

Type Parameters

T
The type of elements in the collection.

Remarks

  Note

In NET Framework 3.5 this class is not available because it would require to reference System.WindowsBase.dll.

The ObservableBindingListT can be used in any environment where either IBindingList or INotifyCollectionChanged (mainly ObservableCollectionT) types are supported.

If initialized by another IBindingList or INotifyCollectionChanged implementations, the ObservableBindingListT will capture and delegate also the events of the inner collections.

If the ObservableBindingListT is initialized by the default constructor it will use a SortableBindingListT inside.

  Tip

In an environment, which supports only the IBindingList or INotifyCollectionChanged interface but not the other, ObservableBindingListT can be used as a bridge between the two worlds. For example, by passing an ObservableCollectionT to the constructor, it will be able to be accessed as an IBindingList implementation, and vice-versa: by wrapping an IBindingList instance (such as FastBindingListT or SortableBindingListT), it can be used as an INotifyCollectionChanged implementation by the ObservableBindingListT class.

Differences to the ObservableCollectionT class:

Differences to the BindingListT class:

IDisposable support:
The ObservableBindingListT implements the IDisposable interface. When an instance is disposed, then both incoming and outgoing event subscriptions (self events and PropertyChanged event of the elements) are removed. If the wrapped collection passed to the constructor is disposable, then it will also be disposed. After disposing accessing the public members may throw ObjectDisposedException.

Constructors

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

Properties

AllowEdit Gets or sets whether item properties can be edited in the list.
If the underlying list implements IBindingList and its AllowEdit returns , then this property returns also . Otherwise, the default value is .
AllowNew Gets or sets whether new items can be added to the list by the AddNew method.
If the underlying list implements IBindingList and its AllowNew returns , then this property returns also . Otherwise, the default value is if the wrapped list is not read-only and T is a value type or has a parameterless constructor; otherwise, .
AllowRemove Gets or sets whether items can be removed from the list by the Remove, RemoveAt and Clear methods.
If the underlying list implements IBindingList and its AllowRemove returns , then this property returns also . Otherwise, the default value is .
PropertyDescriptors Gets the property descriptors of T.
RaiseCollectionChangedEvents Gets or sets whether adding or removing items within the list raises CollectionChanged events.
Default value: .
RaiseItemChangedEvents Gets or sets whether ListChanged and CollectionChanged events are invoked with ItemChanged/Replace change type when a property of an item changes.
If T does not implement INotifyPropertyChanged, then this property returns . Otherwise, the default value is .
RaiseListChangedEvents Gets or sets whether adding or removing items within the list raises ListChanged events.
Default value: .

Methods

AddNew Adds a new item to the collection.
BlockReentrancy Disallows reentrant attempts to change this collection.
CancelNew Discards a pending new item added by the AddNew method.
CheckReentrancy Checks for reentrant attempts to change this collection.
ClearItems Removes all elements from the ObservableBindingListT.
(Overrides CollectionTClearItems)
Dispose Releases the list and removes both incoming and outgoing subscriptions.
Dispose(Boolean) Releases the resources used by this ObservableBindingListT instance.
EndNew Commits a pending new item added by the AddNew method.
InsertItem Inserts an element into the ObservableBindingListT at the specified index.
(Overrides CollectionTInsertItem(Int32, T))
Move Moves the item at the specified index to a new location in the ObservableBindingListT.
MoveItem Moves the item at the specified index to a new location in the ObservableBindingListT.
OnCollectionChanged Raises the CollectionChanged event.
OnListChanged Raises the ListChanged event.
OnPropertyChanged Raises the PropertyChanged event.
RemoveItem Removes the element at the specified index from the ObservableBindingListT.
(Overrides CollectionTRemoveItem(Int32))
ResetBindings Raises the ListChanged event of type Reset and the CollectionChanged event of type Reset.
ResetItem Raises the ListChanged event of type ItemChanged and the CollectionChanged event of type Replace at the specified position.
SetItem Replaces the item at the specified index.
(Overrides CollectionTSetItem(Int32, T))

Events

CollectionChanged Occurs when the list or an item in the list changes.
ListChanged Occurs when the list or an item in the list changes.
PropertyChanged Occurs when a property value changes. Occurs also when the elements in the list changes, in which case the value of the PropertyName will be Item[].

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)
CreatePropertyBinding Creates a special binding for the PropertyChanged event of the specified source, which allows to update the specified targetPropertyName in the targets, when the property of sourcePropertyName changes in the source.
(Defined by Command)
CreatePropertyBinding Creates a special binding for the PropertyChanged event of the specified source, which allows to update the specified targetPropertyName in the targets, when the property of sourcePropertyName changes in the source.
(Defined by Command)
CreatePropertyChangedHandlerBinding Creates a special command binding for the PropertyChanged event of the specified source that invokes the specified handler only when the changed property is among the specified propertyNames.
(Defined by Command)
CreatePropertyChangedHandlerBinding Creates a special command binding for the PropertyChanged event of the specified source that invokes the specified handler only when the changed property is among the specified propertyNames.
(Defined by Command)
CreateSynchronizedPropertyBinding Creates a special binding for the PropertyChanged event of the specified source, which allows to update the specified targetPropertyName in the targets, when the property of sourcePropertyName changes in the source. The target properties will be set using the SynchronizationContext of the thread on which this method was called.
(Defined by Command)
CreateSynchronizedPropertyBinding Creates a special binding for the PropertyChanged event of the specified source, which allows to update the specified targetPropertyName in the targets, when the property of sourcePropertyName changes in the source. The target properties will be set using the SynchronizationContext of the thread on which this method was called.
(Defined by Command)
CreateTwoWayPropertyBinding Creates a pair of special bindings for the PropertyChanged event of the specified source and target, which allow to update the specified targetPropertyName and sourcePropertyName in both directions when any of them changes.
(Defined by Command)
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)
IndexOf Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions)
IndexOf Searches for an element in the source enumeration.
(Defined by EnumerableExtensions)
IsNullOrEmpty Determines whether the specified source is or empty (has no elements).
(Defined by EnumerableExtensions)
TryAdd Tries to add the specified item to the collection.
(Defined by EnumerableExtensions)
TryAddRange Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions)
TryClear Tries to remove all elements from the collection.
(Defined by EnumerableExtensions)
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)
TryGetCount Tries to get the number of elements in the source enumeration without enumerating it.
(Defined by EnumerableExtensions)
TryGetElementAt Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions)
TryInsert Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions)
TryInsertRange Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions)
TryRemove Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions)
TryRemoveAt Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions)
TryRemoveRange Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions)
TryReplaceRange Tries to remove count amount of items from the target at the specified index, and to insert the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by EnumerableExtensions)
TrySetElementAt Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions)

See Also