Class
ObservableCollection<T>

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

Definition

Namespace:Telerik.WinControls.Data

Assembly:Telerik.WinControls.dll

Type Parameters:

T

The type of elements in the collection.

Syntax:

cs-api-definition
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

ObservableCollection()

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

Declaration

cs-api-definition
public ObservableCollection()

ObservableCollection(IEnumerable<T>)

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

Declaration

cs-api-definition
public ObservableCollection(IEnumerable<T> list)

Parameters

list

IEnumerable<T>

The enumerable from which the elements are copied.

ObservableCollection(IList<T>)

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

Declaration

cs-api-definition
public ObservableCollection(IList<T> list)

Parameters

list

IList<T>

The list from which the elements are copied.

ObservableCollection(ObservableCollection<T>)

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

Declaration

cs-api-definition
public ObservableCollection(ObservableCollection<T> list)

Parameters

list

ObservableCollection<T>

Fields

CountString

Declaration

cs-api-definition
protected const string CountString = "Count"

Field Value

string

ItemArrayString

Declaration

cs-api-definition
protected const string ItemArrayString = "Item[]"

Field Value

string

Properties

IsUpdated

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

Declaration

cs-api-definition
public bool IsUpdated { get; }

Property Value

bool

Methods

AddRange(IEnumerable<T>)

Declaration

cs-api-definition
public virtual void AddRange(IEnumerable<T> items)

Parameters

items

IEnumerable<T>

BeginItemUpdate()

Declaration

cs-api-definition
public virtual void BeginItemUpdate()

BeginUpdate()

Suspends event notification.

Declaration

cs-api-definition
public virtual void BeginUpdate()

CallCollectionChanged(object, NotifyCollectionChangedEventArgs)

Declaration

cs-api-definition
protected void CallCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)

Parameters

sender

object

e

NotifyCollectionChangedEventArgs

CallCollectionChanging(object, NotifyCollectionChangingEventArgs)

Declaration

cs-api-definition
protected void CallCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)

Parameters

sender

object

e

NotifyCollectionChangingEventArgs

ClearItems()

Overridden. Removes all items from the collection.

Declaration

cs-api-definition
protected override void ClearItems()

Overrides Collection<T>.ClearItems()

EndItemUpdate()

Declaration

cs-api-definition
public void EndItemUpdate()

EndItemUpdate(bool)

Resumes event notification.

Declaration

cs-api-definition
public virtual void EndItemUpdate(bool notifyUpdates)

Parameters

notifyUpdates

bool

EndUpdate()

Declaration

cs-api-definition
public void EndUpdate()

EndUpdate(bool)

Resumes event notification.

Declaration

cs-api-definition
public virtual void EndUpdate(bool notifyUpdates)

Parameters

notifyUpdates

bool

InsertItem(int, T)

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

Declaration

cs-api-definition
protected override void InsertItem(int index, T item)

Parameters

index

int

item

T

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

InsertItem(int, T, Action<T>)

Declaration

cs-api-definition
protected virtual void InsertItem(int index, T item, Action<T> approvedAction)

Parameters

index

int

item

T

approvedAction

Action<T>

Move(int, int)

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

Declaration

cs-api-definition
public void Move(int oldIndex, int newIndex)

Parameters

oldIndex

int

newIndex

int

MoveItem(int, int)

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

Declaration

cs-api-definition
protected virtual void MoveItem(int oldIndex, int newIndex)

Parameters

oldIndex

int

newIndex

int

NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs)

Raises the CollectionChanged event with the provided arguments.

Declaration

cs-api-definition
protected virtual void NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs e)

Parameters

e

NotifyCollectionChangedEventArgs

NotifyListenersCollectionChanging(NotifyCollectionChangingEventArgs)

Raises the CollectionChanging event with the provided arguments.

Declaration

cs-api-definition
protected virtual void NotifyListenersCollectionChanging(NotifyCollectionChangingEventArgs e)

Parameters

e

NotifyCollectionChangingEventArgs

OnCollectionChanged(NotifyCollectionChangedAction, object, int)

Declaration

cs-api-definition
protected void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index)

Parameters

action

NotifyCollectionChangedAction

item

object

index

int

OnCollectionChanged(NotifyCollectionChangedAction, object, int, int)

Declaration

cs-api-definition
protected void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index, int oldIndex)

Parameters

action

NotifyCollectionChangedAction

item

object

index

int

oldIndex

int

OnCollectionChanged(NotifyCollectionChangedAction, object, object, int)

Declaration

cs-api-definition
protected void OnCollectionChanged(NotifyCollectionChangedAction action, object oldItem, object newItem, int index)

Parameters

action

NotifyCollectionChangedAction

oldItem

object

newItem

object

index

int

OnCollectionChanged(NotifyCollectionChangedEventArgs)

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

Declaration

cs-api-definition
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)

Parameters

e

NotifyCollectionChangedEventArgs

OnCollectionChanging(NotifyCollectionChangedAction, object, int)

Declaration

cs-api-definition
protected bool OnCollectionChanging(NotifyCollectionChangedAction action, object item, int index)

Parameters

action

NotifyCollectionChangedAction

item

object

index

int

Returns

bool

OnCollectionChanging(NotifyCollectionChangedAction, object, int, int)

Declaration

cs-api-definition
protected bool OnCollectionChanging(NotifyCollectionChangedAction action, object item, int index, int oldIndex)

Parameters

action

NotifyCollectionChangedAction

item

object

index

int

oldIndex

int

Returns

bool

OnCollectionChanging(NotifyCollectionChangedAction, object, object, int)

Declaration

cs-api-definition
protected bool OnCollectionChanging(NotifyCollectionChangedAction action, object oldItem, object newItem, int index)

Parameters

action

NotifyCollectionChangedAction

oldItem

object

newItem

object

index

int

Returns

bool

OnCollectionChanging(NotifyCollectionChangingEventArgs)

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

Declaration

cs-api-definition
protected virtual bool OnCollectionChanging(NotifyCollectionChangingEventArgs e)

Parameters

e

NotifyCollectionChangingEventArgs

Returns

bool

OnCollectionReset(IList)

Declaration

cs-api-definition
protected void OnCollectionReset(IList oldItems)

Parameters

oldItems

IList

OnCollectionReseting()

Declaration

cs-api-definition
protected bool OnCollectionReseting()

Returns

bool

OnNotifyPropertyChanged(PropertyChangedEventArgs)

Raises the NotifyPropertyChanged event

Declaration

cs-api-definition
protected virtual void OnNotifyPropertyChanged(PropertyChangedEventArgs e)

Parameters

e

PropertyChangedEventArgs

A PropertyChangedEventArgs instance containing event data.

OnNotifyPropertyChanged(string)

Raises the PropertyChanged event

Declaration

cs-api-definition
protected virtual void OnNotifyPropertyChanged(string propertyName)

Parameters

propertyName

string

The name of the property

OnNotifyPropertyChanging(PropertyChangingEventArgsEx)

Raises the NotifyPropertyChanging event

Declaration

cs-api-definition
protected virtual void OnNotifyPropertyChanging(PropertyChangingEventArgsEx e)

Parameters

e

PropertyChangingEventArgsEx

A PropertyChangingEventArgs instance containing event data.

OnNotifyPropertyChanging(string)

Raises the PropertyChanging event

Declaration

cs-api-definition
protected virtual void OnNotifyPropertyChanging(string propertyName)

Parameters

propertyName

string

The name of the property

RemoveItem(int)

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

Declaration

cs-api-definition
protected override void RemoveItem(int index)

Parameters

index

int

Overrides Collection<T>.RemoveItem(int)

RemoveRange(IEnumerable<T>)

Declaration

cs-api-definition
public virtual void RemoveRange(IEnumerable<T> items)

Parameters

items

IEnumerable<T>

SetItem(int, T)

Overridden. Replaces the element at the specified index.

Declaration

cs-api-definition
protected override void SetItem(int index, T item)

Parameters

index

int

item

T

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

Events

CollectionChanged

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

Declaration

cs-api-definition
public event NotifyCollectionChangedEventHandler CollectionChanged

Event Value

NotifyCollectionChangedEventHandler

Implements INotifyCollectionChanged.CollectionChanged

CollectionChanging

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

Declaration

cs-api-definition
public event NotifyCollectionChangingEventHandler CollectionChanging

Event Value

NotifyCollectionChangingEventHandler

Implements INotifyCollectionChanging.CollectionChanging

PropertyChanged

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

Declaration

cs-api-definition
[Browsable(false)]
public event PropertyChangedEventHandler PropertyChanged

Event Value

PropertyChangedEventHandler

Implements INotifyPropertyChanged.PropertyChanged

PropertyChanging

Occurs before a property of an object changes.

Declaration

cs-api-definition
public event PropertyChangingEventHandlerEx PropertyChanging

Event Value

PropertyChangingEventHandlerEx

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)InsertItem(int, T, Action<T>)Move(int, int)MoveItem(int, int)NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs)NotifyListenersCollectionChanging(NotifyCollectionChangingEventArgs)OnCollectionChanged(NotifyCollectionChangedAction, object, int)OnCollectionChanged(NotifyCollectionChangedAction, object, int, int)OnCollectionChanged(NotifyCollectionChangedAction, object, object, int)OnCollectionChanged(NotifyCollectionChangedEventArgs)OnCollectionChanging(NotifyCollectionChangedAction, object, int)OnCollectionChanging(NotifyCollectionChangedAction, object, int, 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