New to Telerik UI for WinForms? Start a free 30-day trial

Represents a dynamic data collection that provides notifications when items are added, removed, or when the list is refreshed.

This implementation provides both collection change notifications and property change notifications, supporting advanced scenarios like batch updates and item-level change tracking.

Definition

Namespace:Telerik.WinControls.Data

Assembly:Telerik.WinControls.dll

Type Parameters:

T

The type of elements in the collection.

Syntax:

C#
public class ObservableCollection<T> : Collection<T>, IList, ICollection, IEnumerable, INotifyCollectionChanged, INotifyCollectionChanging, INotifyPropertyChanged, INotifyPropertyChangingEx

Inheritance: objectCollection<T>ObservableCollection<T>

Derived Classes: FilterParameterDictionaryFilterPredicateCollectionCellDefinitionsCollectionColumnCollectionColumnGroupCollectionColumnNameCollectionGanttViewTextViewColumnCollectionGridViewColumnCollectionGridViewSummaryRowItemGridViewSummaryRowItemCollectionGridViewTemplateCollectionGroupsCollectionItemObservableCollection<T>LegendItemCollectionListViewColumnCollectionRadListDataItemSelectedCollectionRowDefinitionsCollectionSchedulerBackgroundCollectionSchedulerObservableCollectionSchedulerReminderCollectionSchedulerResourceCollectionSchedulerStatusCollectionSchedulerTimeZoneCollectionWaitingBarIndicatorCollectionWaitingIndicatorCollectionWizardPageCollectionPropertySerializationMetadataCollection...

Implements: ICollectionIEnumerableIListINotifyCollectionChangedINotifyCollectionChangingINotifyPropertyChangedINotifyPropertyChangingEx...

Inherited Members Collection<T>.Add(T)Collection<T>.Clear()Collection<T>.CopyTo(T[], int)Collection<T>.Contains(T)Collection<T>.GetEnumerator()Collection<T>.IndexOf(T)Collection<T>.Insert(int, T)Collection<T>.Remove(T)Collection<T>.RemoveAt(int)Collection<T>.CountCollection<T>.ItemsCollection<T>.this[int]...

Constructors

Initializes a new instance of the ObservableCollection<T> class.

C#
public ObservableCollection()

Initializes a new instance of the ObservableCollection<T> class that contains elements copied from the specified enumerable.

C#
public ObservableCollection(IEnumerable<T> list)
Parameters:listIEnumerable<T>

The enumerable from which the elements are copied.

Initializes a new instance of the ObservableCollection<T> class that contains elements copied from the specified list.

C#
public ObservableCollection(IList<T> list)
Parameters:listIList<T>

The list from which the elements are copied.

Initializes a new instance of the ObservableCollection class that contains elements copied from the specified list.

C#
public ObservableCollection(ObservableCollection<T> list)
Parameters:listObservableCollection<T>

Fields

C#
protected const string CountString = "Count"
C#
protected const string ItemArrayString = "Item[]"

Properties

true to indicate the collection has completed update; otherwise false.

C#
public bool IsUpdated { get; }

Methods

C#
public virtual void AddRange(IEnumerable<T> items)
Parameters:itemsIEnumerable<T>
C#
public virtual void BeginItemUpdate()

Suspends event notification.

C#
public virtual void BeginUpdate()
C#
protected void CallCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Parameters:senderobjecteNotifyCollectionChangedEventArgs
C#
protected void CallCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
Parameters:senderobjecteNotifyCollectionChangingEventArgs

Overridden. Removes all items from the collection.

C#
protected override void ClearItems()

Overrides: Collection<T>.ClearItems()

C#
public void EndItemUpdate()

Resumes event notification.

C#
public virtual void EndItemUpdate(bool notifyUpdates)
Parameters:notifyUpdatesbool
C#
public void EndUpdate()

Resumes event notification.

C#
public virtual void EndUpdate(bool notifyUpdates)
Parameters:notifyUpdatesbool
C#
protected virtual void InsertItem(int index, T item, Action<T> approvedAction)
Parameters:indexintitemTapprovedActionAction<T>

Overridden. Inserts an item into the collection at the specified index.

C#
protected override void InsertItem(int index, T item)
Parameters:indexintitemT

Overrides: Collection<T>.InsertItem(int, T)

Moves the item at the specified index to a new location in the collection.

C#
public void Move(int oldIndex, int newIndex)
Parameters:oldIndexintnewIndexint

Moves the item at the specified index to a new location in the collection.

C#
protected virtual void MoveItem(int oldIndex, int newIndex)
Parameters:oldIndexintnewIndexint

Raises the CollectionChanged event with the provided arguments.

C#
protected virtual void NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters:eNotifyCollectionChangedEventArgs

Raises the CollectionChanging event with the provided arguments.

C#
protected virtual void NotifyListenersCollectionChanging(NotifyCollectionChangingEventArgs e)
Parameters:eNotifyCollectionChangingEventArgs
C#
protected void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index, int oldIndex)
Parameters:actionNotifyCollectionChangedActionitemobjectindexintoldIndexint
C#
protected void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index)
Parameters:actionNotifyCollectionChangedActionitemobjectindexint
C#
protected void OnCollectionChanged(NotifyCollectionChangedAction action, object oldItem, object newItem, int index)
Parameters:actionNotifyCollectionChangedActionoldItemobjectnewItemobjectindexint

Calls the NotifyListenersCollectionChanged method with the provided arguments if not in a batch update.

C#
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters:eNotifyCollectionChangedEventArgs
C#
protected bool OnCollectionChanging(NotifyCollectionChangedAction action, object item, int index, int oldIndex)
Parameters:actionNotifyCollectionChangedActionitemobjectindexintoldIndexintReturns:

bool

C#
protected bool OnCollectionChanging(NotifyCollectionChangedAction action, object item, int index)
Parameters:actionNotifyCollectionChangedActionitemobjectindexintReturns:

bool

C#
protected bool OnCollectionChanging(NotifyCollectionChangedAction action, object oldItem, object newItem, int index)
Parameters:actionNotifyCollectionChangedActionoldItemobjectnewItemobjectindexintReturns:

bool

Calls the NotifyListenersCollectionChanging method with the provided arguments if not in a batch update.

C#
protected virtual bool OnCollectionChanging(NotifyCollectionChangingEventArgs e)
Parameters:eNotifyCollectionChangingEventArgsReturns:

bool

C#
protected void OnCollectionReset(IList oldItems)
Parameters:oldItemsIList
C#
protected bool OnCollectionReseting()
Returns:

bool

Raises the NotifyPropertyChanged event

C#
protected virtual void OnNotifyPropertyChanged(PropertyChangedEventArgs e)
Parameters:ePropertyChangedEventArgs

A PropertyChangedEventArgs instance containing event data.

Raises the PropertyChanged event

C#
protected virtual void OnNotifyPropertyChanged(string propertyName)
Parameters:propertyNamestring

The name of the property

Raises the NotifyPropertyChanging event

C#
protected virtual void OnNotifyPropertyChanging(PropertyChangingEventArgsEx e)
Parameters:ePropertyChangingEventArgsEx

A PropertyChangingEventArgs instance containing event data.

Raises the PropertyChanging event

C#
protected virtual void OnNotifyPropertyChanging(string propertyName)
Parameters:propertyNamestring

The name of the property

Overridden. Removes the item at the specified index of the collection.

C#
protected override void RemoveItem(int index)
Parameters:indexint

Overrides: Collection<T>.RemoveItem(int)

C#
public virtual void RemoveRange(IEnumerable<T> items)
Parameters:itemsIEnumerable<T>

Overridden. Replaces the element at the specified index.

C#
protected override void SetItem(int index, T item)
Parameters:indexintitemT

Overrides: Collection<T>.SetItem(int, T)

Events

Occurs when an item is added, removed, changed, moved, or the entire list is refreshed.

C#
public event NotifyCollectionChangedEventHandler CollectionChanged

Implements: INotifyCollectionChanged.CollectionChanged

Occurs before an item is added, removed, changed, moved, or the entire list is refreshed.

C#
public event NotifyCollectionChangingEventHandler CollectionChanging

Implements: INotifyCollectionChanging.CollectionChanging

Occurs when a property of an object changes. Calling the event is developer's responsibility.

C#
[Browsable(false)]
public event PropertyChangedEventHandler PropertyChanged

Implements: INotifyPropertyChanged.PropertyChanged

Occurs before a property of an object changes.

C#
public event PropertyChangingEventHandlerEx PropertyChanging

Implements: INotifyPropertyChangingEx.PropertyChanging

In this article
DefinitionConstructorsObservableCollection()ObservableCollection(IEnumerable<T>)ObservableCollection(IList<T>)ObservableCollection(ObservableCollection<T>)FieldsCountStringItemArrayStringPropertiesIsUpdatedMethodsAddRange(IEnumerable<T>)BeginItemUpdate()BeginUpdate()CallCollectionChanged(object, NotifyCollectionChangedEventArgs)CallCollectionChanging(object, NotifyCollectionChangingEventArgs)ClearItems()EndItemUpdate()EndItemUpdate(bool)EndUpdate()EndUpdate(bool)InsertItem(int, T, Action<T>)InsertItem(int, T)Move(int, int)MoveItem(int, int)NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs)NotifyListenersCollectionChanging(NotifyCollectionChangingEventArgs)OnCollectionChanged(NotifyCollectionChangedAction, object, int, int)OnCollectionChanged(NotifyCollectionChangedAction, object, int)OnCollectionChanged(NotifyCollectionChangedAction, object, object, int)OnCollectionChanged(NotifyCollectionChangedEventArgs)OnCollectionChanging(NotifyCollectionChangedAction, object, int, int)OnCollectionChanging(NotifyCollectionChangedAction, object, int)OnCollectionChanging(NotifyCollectionChangedAction, object, object, int)OnCollectionChanging(NotifyCollectionChangingEventArgs)OnCollectionReset(IList)OnCollectionReseting()OnNotifyPropertyChanged(PropertyChangedEventArgs)OnNotifyPropertyChanged(string)OnNotifyPropertyChanging(PropertyChangingEventArgsEx)OnNotifyPropertyChanging(string)RemoveItem(int)RemoveRange(IEnumerable<T>)SetItem(int, T)EventsCollectionChangedCollectionChangingPropertyChangedPropertyChanging
Not finding the help you need?
Contact Support