CollectionChangedEventArgs Class

Current information about Live Connect is now available in the Windows Live Developer Center. The information in the following sections is provided for legacy purposes only.

Provides data for the collectionChanged event of a DataCollection instance.

Feature:  Microsoft.Live.Services
Namespace:  Microsoft.Live.Services

The JavaScript Library for Windows Live Messenger Connect is built by using the Microsoft Ajax Library. Microsoft Ajax exposes a type system that enables you to add object-oriented capabilities to your JavaScript code. To learn more about creating, instantiating, and deriving from classes, see Creating Custom Client Script by Using the Microsoft Ajax Library.

Microsoft.Live.Services.CollectionChangedEventArgs = function();


The argument for an event handler for the collectionChanged event is a CollectionChangedEventArgs object. The event handler that you provide is invoked for each add, remove, update action on the collection. For example, suppose you have a ContactCollection instance that contains two Contact items. Now you add two items to a collection by using the Microsoft.Live.Services.DataCollection.add method, and then update one of the original two items. The handler you provide for the collectionChanged event is called twice, once for the add operation and once for the update operation.

The following example demonstrates how to subscribe to the collectionChanged event of the collection and then display changes to the collection. This example assumes that the page contains an element named Output whose innerHtml property can be set.

var out, sb, br = "</br>";
function appLoaded(applicationLoadCompletedEventArgs) {
    out = document.getElementById("Output");
function testContactCollection() {
    Microsoft.Live.Core.Loader.load(["Microsoft.Live.Services"], function () {
        Microsoft.Live.App.get_auth().getConsent(function (args) {
            Microsoft.Live.App.get_dataContext().loadAll(Microsoft.Live.DataType.contacts, function (args) {
                var contactCollection = args.get_data();                
function collectionChanged(collectionChangedEventArgs) {
    if (collectionChangedEventArgs !== null) {
        var changedCollection = collectionChangedEventArgs.get_changedCollection();
        var changeType = Microsoft.Live.Services.CollectionChangeType.toString(collectionChangedEventArgs.get_changeType());
        var countChanged = collectionChangedEventArgs.get_changedItems().length;
        var firstChangedItemName = (collectionChangedEventArgs.get_changedItems()[0]).get_firstName();

        sb = "ChangeType = " + changeType + br;
        sb += "Number of Changed Items = " + countChanged + br;
        sb += "First Changed Item = " + firstChangedItemName + br;
        sb += "The full collection: " + br;
        for (var i = 0; i < changedCollection.get_length(); i++) {
            contact = changedCollection.getItem(i);
            sb += contact.get_firstName() + ", " + contact.get_lastName() + br;
        out.innerHTML += sb;


Windows Live Messenger Connect

Supported in: 4.1

Internet Explorer 8.0, Internet Explorer 7.0, Internet Explorer 6.0, Firefox 3.6, Firefox 3.5, Firefox 3.0, Firefox 2.0, Firefox 1.5, Chrome 4.0, Chrome 3.0, Chrome 2.0, Chrome 1.0, Safari 4.0, Safari 3.0