Partager via


Update a Data Source Collection (Compact 7)

3/12/2014

You can update the items in a data source collection. For example, if a user adds or deletes media files in a playlist and then reloads the playlist on a device, the media application can update the collection.

To update a data source collection

  1. In Platform Builder, open your OS design project.

  2. In your subproject, open the source code file where you want to add functionality for updating the data source collection. For example, in Solution Explorer, browse to Subprojects\<Subproject Name>\Source files, and open MainPage.cpp.

  3. To block other threads from accessing the collection object, implement a thread safety mechanism. For example, create an XRAutoCriticalSection object and call EnterCriticalSection.

  4. Obtain a pointer to the XRObservableCollection<ItemType> collection. For example, call the derived method IXRItemsControl::GetItemsSource.

  5. Update the data source collection by doing the following:

    1. To add a new item, call the derived method XRValueCollectionT.Add(const ItemType&).

    2. To remove an item, call the derived method XRValueCollectionT.Remove(const ItemType&).

    3. To replace an item, call the derived method XRValueCollectionT.SetItem(int,const ItemType&).

  6. To raise the CollectionChanged event, call XRObservableCollection.OnCollectionChanged(XRCollectionChangedCustomEventArgs *).

  7. Release ownership of the thread. For example, call LeaveCriticalSection.

See Also

Concepts

Update the Data (Optional)