I get a SPListItemCollection in my program. I use this collection to show the items in a DataGridView display.

I need to filter items based on a requirement. But .Add() or Delete() does changes to the actual list items. So what would be the best way to temporarily store editions to this list, so that it can be used for display in the DataGridView.

The SPListItemCollection.GetDataTable() method make it wasy to set the DataSource at the grid


Your question has the answer, once you get SPListItemCollection.GetDataTable(), store this DataTable in a cache and do the updates on this table temporarily!

Once you are done with the updates and save, you can iterate through the table to save the records in the list. Make sure when you are done, you clear the cache..

  • Actually there is a series of method calls where SPListItemCollection is returned. I was wondering if the SPListItemCollection could be sent to the caller methods where finally it could be set to the GridView using the GetDataTable() – Shaamil Feb 10 '14 at 13:17
  • AFAIK, I don't think its possible.. However you can get data table all the time from SPListItemCollection and use DataTable.Merge function to merge the two! – Arsalan Adam Khatri Feb 10 '14 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.