Class ArrayListExt
Extends ArrayList by throwing events when Collection changes, an item's property changes, etc.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Collections
Assembly: Syncfusion.Shared.Base.dll
Syntax
public class ArrayListExt : ArrayList, IList, ICollection, IEnumerable, ICloneable
Remarks
This class lets you know through the CollectionChanged event when an item gets added or deleted from the ArrayList or when an exisiting item is replaced by a new item at a position. It will also listen for property change notifications from the items in the list, provided the items implement the IChangeNotifyingItem interface and forward them using the ItemPropertyChanged event.
Constructors
ArrayListExt()
Overloaded. Creates a new instance of the ArrayListExt class.
Declaration
public ArrayListExt()
ArrayListExt(Object[])
Creates a new instance of the ArrayListExt class and inserts the items specified in an array into the ArrayList.
Declaration
public ArrayListExt(object[] items)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | items | An array of objects. |
Properties
ForceFixedSize
Indicates whether the collection should be made fixed size.
Declaration
protected bool ForceFixedSize { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True to make the collection fixed size; False otherwise. Default is False. |
Remarks
When set to True, the IsFixedSize property will return True and no new elements can be added to the list.
ForceReadOnly
Indicates whether the collection is Read-only.
Declaration
protected bool ForceReadOnly { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True to make the collection Read-only; False otherwise. Default is False. |
Remarks
When set to True, the IsReadOnly property will return True and exisiting items in the list cannot be replaced.
IsCollectionChangedEventSuspended
Indicates whether firing CollectionChanged event is suspended.
Declaration
public bool IsCollectionChangedEventSuspended { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True indicates firing the event is suspended; False otherwise. |
IsFixedSize
Declaration
public override bool IsFixedSize { get; }
Property Value
Type |
---|
System.Boolean |
Overrides
IsReadOnly
Declaration
public override bool IsReadOnly { get; }
Property Value
Type |
---|
System.Boolean |
Overrides
Item[Int32]
Overridden. See System.Collections.ArrayList.Item.
Declaration
public override object this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Property Value
Type |
---|
System.Object |
Overrides
Methods
Add(Object)
Overridden. See System.Collections.ArrayList.Add.
Declaration
public override int Add(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value |
Returns
Type |
---|
System.Int32 |
Overrides
AddHandlers(Object)
Called when an object gets added to the list.
Declaration
protected virtual void AddHandlers(object item)
Parameters
Type | Name | Description |
---|---|---|
System.Object | item | The object that got added to the list. |
Remarks
This provides you a convenient place where you can perform operations pertaining to the addition of an object to the list. Make sure to call the base class when you override this function.
The method will call the OnCollectionChanged(CollectionChangeEventArgs) method with appropriate parameters.
Clear()
Overridden. See System.Collections.ArrayList.Clear().
Declaration
public override void Clear()
Overrides
Insert(Int32, Object)
Overridden. See System.Collections.ArrayList.Insert.
Declaration
public override void Insert(int index, object value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
System.Object | value |
Overrides
InsertRange(Int32, ICollection)
Overridden. See System.Collections.ArrayList.InsertRange.
Declaration
public override void InsertRange(int index, ICollection c)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
System.Collections.ICollection | c |
Overrides
Move(Int32, Int32, Int32)
Allows you to move one or more items in the collection from one position to another.
Declaration
public virtual void Move(int from, int to, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | from | The beginning index of the range of items to move. |
System.Int32 | to | The destination index where the items will be moved to. |
System.Int32 | count | The number of elements in the range to be moved. |
Remarks
If the above indices are not within the list's count, this method will return without performing any operation.
For example, say a list contains the following elements: A, B, C, D, E, F. Then the following call:
list.Move(2, 4, 2);
will result in the following array: A, B, E, F, C, D.
OnCollectionChanged(CollectionChangeEventArgs)
Raises the CollectionChanged event.
Declaration
protected virtual void OnCollectionChanged(CollectionChangeEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.ComponentModel.CollectionChangeEventArgs | args | A System.ComponentModel.CollectionChangeEventArgs object containing data pertaining to this event. |
Remarks
The OnCollectionChanged(CollectionChangeEventArgs) method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Note to Inheritors: When overriding OnCollectionChanged in a derived class, be sure to call the base class's OnCollectionChanged method so that registered delegates receive the event.
OnCollectionChanging()
Called when an item is being added, removed, moved or when an exisiting item is replaced by a new item.
Declaration
protected virtual void OnCollectionChanging()
Remarks
This method does not fire a corresponding event.
OnItemPropertyChanged(Object, SyncfusionPropertyChangedEventArgs)
Raises the ItemPropertyChanged event.
Declaration
protected virtual void OnItemPropertyChanged(object sender, SyncfusionPropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | The source of the event. |
SyncfusionPropertyChangedEventArgs | e | The SyncfusionPropertyChangedEventArgs object that contains data pertaining to this event. |
Remarks
The OnItemPropertyChanged(Object, SyncfusionPropertyChangedEventArgs) method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Note to Inheritors: When overriding OnItemPropertyChanged(Object, SyncfusionPropertyChangedEventArgs) in a derived class, be sure to call the base class's OnItemPropertyChanged(Object, SyncfusionPropertyChangedEventArgs) method so that registered delegates receive the event.
RaiseCollectionChanged(CollectionChangeEventArgs)
Call this method to force a CollectionChanged event.
Declaration
public void RaiseCollectionChanged(CollectionChangeEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.ComponentModel.CollectionChangeEventArgs | args | The args for the above mentioned event. |
Remarks
This method is useful when after suspending and resuming events in this list, you might want to fire the CollectionChanged event for some specific changes.
ReleaseHandler(Object)
Called when an item gets removed from the list.
Declaration
protected virtual void ReleaseHandler(object item)
Parameters
Type | Name | Description |
---|---|---|
System.Object | item | The object that got removed from the list. |
Remarks
This provides you a convenient place where you can perform operations pertaining to the removal of an object from the list. Make sure to call the base class when you override this function.
The base class will call the OnCollectionChanged(CollectionChangeEventArgs) event with appropriate parameters.
RemoveAt(Int32)
Overridden. See System.Collections.ArrayList.RemoveAt
Declaration
public override void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Overrides
RemoveRange(Int32, Int32)
Overridden. See System.Collections.ArrayList.RemoveRange.
Declaration
public override void RemoveRange(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
System.Int32 | count |
Overrides
ResumeEvents(Boolean)
Starts throwing the CollectionChanged and ItemPropertyChanged events.
Declaration
public void ResumeEvents(bool throwEvent)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | throwEvent | True will throw a CollectionChanged event; False will not. |
Remarks
Call this method after calling a SuspendEvents() method to resume throwing the CollectionChanged and ItemPropertyChanged events.
Note that there is no one-to-one correspondence between SuspendEvents and ResumeEvents. SuspendEvents could be called more than once but a single subsequent ResumeEvents call will resume throwing events.
Reverse(Int32, Int32)
Reverse range of items in collection from position specified by index parameter and length specified by count parameter.
Declaration
public override void Reverse(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | range start position. |
System.Int32 | count | range length. |
Overrides
Sort(Int32, Int32, IComparer)
Sorts the elements in the entire System.Collections.ArrayList using the System.IComparable implementation of each element.
Declaration
public override void Sort(int index, int count, IComparer comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
System.Int32 | count | |
System.Collections.IComparer | comparer |
Overrides
SuspendEvents()
Will suspend the CollectionChanged and ItemPropertyChanged events temporarily.
Declaration
public void SuspendEvents()
Remarks
Call ResumeEvents(Boolean) when you are ready to receive events again. The SuspendEvents()/ResumeEvents(Boolean) calls are useful when you are performing a series of operations that will result in multiple changes in the collection, throwing multiple events. In such cases, you could use these methods to have a single event thrown at the end of the series of operations.
Note that there is no one-to-one correspondence between SuspendEvents() and ResumeEvents(Boolean). SuspendEvents() could be called more than once but a single subsequent ResumeEvents(Boolean) call will resume throwing events.
Events
CollectionChanged
Will be thrown when the Collection has changed due to the addition or removal of one or more items.
Declaration
public event CollectionChangeEventHandler CollectionChanged
Event Type
Type |
---|
System.ComponentModel.CollectionChangeEventHandler |
ItemPropertyChanged
Will be thrown if the items in the Collection implement IChangeNotifyingItem interface and when their property changes.
Declaration
public event SyncfusionPropertyChangedEventHandler ItemPropertyChanged
Event Type
Type |
---|
SyncfusionPropertyChangedEventHandler |