KGy SOFT

ObservableBindingListT Class

KGy SOFT Core Libraries Help
Inheritance Hierarchy

SystemObject
  System.Collections.ObjectModelCollectionT
    KGySoft.ComponentModelObservableBindingListT

Namespace:  KGySoft.ComponentModel
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.0.0-rc.1
Syntax

[SerializableAttribute]
public class ObservableBindingList<T> : Collection<T>, 
	IDisposable, INotifyCollectionChanged, INotifyPropertyChanged, IBindingList, IList, 
	ICollection, IEnumerable, ICancelAddNew, IRaiseItemChangedEvents

Type Parameters

T
The type of elements in the collection.

The ObservableBindingListT type exposes the following members.

Constructors

  NameDescription
Public methodObservableBindingListT
Initializes a new instance of the ObservableBindingListT class with a SortableBindingListT internally.
Public methodObservableBindingListT(IListT)
Initializes a new instance of the ObservableBindingListT class with the specified list.
Top
Properties

  NameDescription
Public propertyAllowEdit
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 .
Public propertyAllowNew
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, .
Public propertyAllowRemove
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 .
Public propertyCount (Inherited from CollectionT.)
Public propertyItem
Gets or sets the element at the specified index.
(Inherited from CollectionT.)
Protected propertyItems (Inherited from CollectionT.)
Protected propertyPropertyDescriptors
Gets the property descriptors of T.
Public propertyRaiseCollectionChangedEvents
Gets or sets whether adding or removing items within the list raises CollectionChanged events.
Default value: .
Public propertyRaiseItemChangedEvents
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 .
Public propertyRaiseListChangedEvents
Gets or sets whether adding or removing items within the list raises ListChanged events.
Default value: .
Top
Methods

  NameDescription
Public methodAdd (Inherited from CollectionT.)
Public methodAddNew
Adds a new item to the collection.
Protected methodBlockReentrancy
Disallows reentrant attempts to change this collection.
Public methodCancelNew
Discards a pending new item added by the AddNew method.
Protected methodCheckReentrancy
Checks for reentrant attempts to change this collection.
Public methodClear (Inherited from CollectionT.)
Protected methodClearItems
Removes all elements from the ObservableBindingListT.
(Overrides CollectionTClearItems.)
Public methodContains (Inherited from CollectionT.)
Public methodCopyTo (Inherited from CollectionT.)
Public methodDispose
Releases the list and removes both incoming and outgoing subscriptions.
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
Public methodEndNew
Commits a pending new item added by the AddNew method.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator (Inherited from CollectionT.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIndexOf (Inherited from CollectionT.)
Public methodInsert (Inherited from CollectionT.)
Protected methodInsertItem
Inserts an element into the ObservableBindingListT at the specified index.
(Overrides CollectionTInsertItem(Int32, T).)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMove
Moves the item at the specified index to a new location in the ObservableBindingListT.
Protected methodMoveItem
Moves the item at the specified index to a new location in the ObservableBindingListT.
Protected methodOnCollectionChanged
Raises the CollectionChanged event.
Protected methodOnListChanged
Raises the ListChanged event.
Protected methodOnPropertyChanged
Raises the PropertyChanged event.
Public methodRemove (Inherited from CollectionT.)
Public methodRemoveAt (Inherited from CollectionT.)
Protected methodRemoveItem
Removes the element at the specified index from the ObservableBindingListT.
(Overrides CollectionTRemoveItem(Int32).)
Public methodResetBindings
Raises the ListChanged event of type Reset and the CollectionChanged event of type Reset.
Public methodResetItem
Raises the ListChanged event of type ItemChanged and the CollectionChanged event of type Replace at the specified position.
Protected methodSetItem
Replaces the item at the specified index.
(Overrides CollectionTSetItem(Int32, T).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Events

  NameDescription
Public eventCollectionChanged
Occurs when the list or an item in the list changes.
Public eventListChanged
Occurs when the list or an item in the list changes.
Public eventPropertyChanged
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[].
Top
Extension Methods

  NameDescription
Public Extension MethodConvert(Type, CultureInfo)Overloaded.
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.)
Public Extension MethodCode exampleConvertTTarget(CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)
Public Extension MethodCreatePropertyBinding(String, String, Object)Overloaded.
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.)
Public Extension MethodCreatePropertyBinding(String, String, FuncObject, Object, Object)Overloaded.
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.)
Public Extension MethodIn (Defined by ObjectExtensions.)
Public Extension MethodIndexOf(FuncObject, Boolean)Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.)
Public Extension MethodIndexOf(Object)Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.)
Public Extension MethodIsNullOrEmpty
Determines whether the specified source is  or empty (has no elements).
(Defined by EnumerableExtensions.)
Public Extension MethodTryAdd
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryAddRange
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryClear
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryConvert(Type, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvert(Type, CultureInfo, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(TTarget)Overloaded.
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.)
Public Extension MethodTryConvertTTarget(CultureInfo, TTarget)Overloaded.
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.)
Public Extension MethodTryGetElementAt
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsert
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsertRange
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemove
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveAt
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveRange
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.)
Public Extension MethodTryReplaceRange
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.)
Public Extension MethodTrySetElementAt
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Top
Remarks

Note Note
In NET 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 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.

See Also

Reference