locked
Remove() method not available for ItemsControl's Items Property in WinRT Visual C++

    Question

  • I can not able to find suitable method to remove an item from ItemsControl's items in WinRT Visual C++.

    (ItemsControlInstance)->Items->remove() method's arugument is Windows::Foundation::EventRegistrationToken. How to use it ?


    b00peshkumar
    Friday, September 30, 2011 12:06 PM

Answers

  • Hi Boopesh,

    If you look at ItemsCollection (the type returned by ItemsControl::Item) in the ObjectBrowser you'll see that there isn't a Remove() method, but there are RemoveAt() and RemoveAtEnd() methods to remove items from given indices.  There is also an IndexOf method to find the method of a given object.  These can be combined to remove a specific item.

    The projection into the .Net Collection API implements Remove(object) for .Net languages.

    See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.itemcollection(v=VS.85).aspx for details on ItemsCollection.

     

    The (lower case) remove() function is to remove an event handler from the ItemsCollection, not an item from the ItemsCollection. 

    --Rob

    • Marked as answer by Boopesh Kumar Wednesday, October 5, 2011 3:36 AM
    Tuesday, October 4, 2011 10:18 PM
    Owner

All replies

  • Hi Boopesh,

    If you look at ItemsCollection (the type returned by ItemsControl::Item) in the ObjectBrowser you'll see that there isn't a Remove() method, but there are RemoveAt() and RemoveAtEnd() methods to remove items from given indices.  There is also an IndexOf method to find the method of a given object.  These can be combined to remove a specific item.

    The projection into the .Net Collection API implements Remove(object) for .Net languages.

    See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.itemcollection(v=VS.85).aspx for details on ItemsCollection.

     

    The (lower case) remove() function is to remove an event handler from the ItemsCollection, not an item from the ItemsCollection. 

    --Rob

    • Marked as answer by Boopesh Kumar Wednesday, October 5, 2011 3:36 AM
    Tuesday, October 4, 2011 10:18 PM
    Owner
  • Adding to what Rob said, the .NET projection does exactly that when you call Remove. It calls IndexOf to check if the object exists, and if it exists, it calls RemoveAt.
    http://blog.voidnish.com
    Tuesday, October 4, 2011 10:51 PM