Back to Devexpress

XPBaseCollection.CollectionChanged Event

xpo-devexpress-dot-xpo-dot-xpbasecollection.md

latest3.0 KB
Original Source

XPBaseCollection.CollectionChanged Event

Occurs when an item is added to, or removed from the XPBaseCollection (when the XPBaseCollection.BaseAdd or XPBaseCollection.BaseRemove method is called).

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public event XPCollectionChangedEventHandler CollectionChanged
vb
Public Event CollectionChanged As XPCollectionChangedEventHandler

Event Data

The CollectionChanged event's data class is XPCollectionChangedEventArgs.

Remarks

To subscribe to this event, override the XPBaseObject.CreateCollection<T> or PersistentBase.CreateCollection method of your persistent class.

csharp
// Example for generic collection:
protected override XPCollection<T> CreateCollection<T>(XPMemberInfo property) {
    XPCollection<T> collection = base.CreateCollection<T>(property);
    if (property.Name == "MyGenericCollectionProperty") {
        collection.CollectionChanged += collection_CollectionChanged;
    }
    return collection;
}
// Example for non-generic collection:
protected override XPCollection CreateCollection(XPMemberInfo property) {
    XPCollection collection = base.CreateCollection(property);
    if (property.Name == "MyCollectionProperty") {
        collection.CollectionChanged += collection_CollectionChanged;
    }
    return collection;
}
vb
' Example for generic collection:
Protected Overrides Function CreateCollection(Of T)(ByVal [property] As XPMemberInfo) As XPCollection(Of T)
    Dim collection As XPCollection(Of T) = MyBase.CreateCollection(Of T)([property])
    If [property].Name = "MyGenericCollectionProperty" Then
        AddHandler collection.CollectionChanged, AddressOf collection_CollectionChanged
    End If
    Return collection
End Function
' Example for non-generic collection:
Protected Overrides Function CreateCollection(ByVal [property] As XPMemberInfo) As XPCollection
    Dim collection As XPCollection = MyBase.CreateCollection([property])
    If [property].Name = "MyCollectionProperty" Then
        AddHandler collection.CollectionChanged, AddressOf collection_CollectionChanged
    End If
    Return collection
End Function

See Also

XPBaseCollection Class

XPBaseCollection Members

DevExpress.Xpo Namespace