How to delete many items in EditableRootList at the same time?

How to delete many items in EditableRootList at the same time?

Old forum URL: forums.lhotka.net/forums/t/867.aspx


phucphlq posted on Wednesday, August 09, 2006

Sorry, my english is not well.

Help me! I have a List<int> with its items are indexes of items in EditableRootList.

I do:

   for(int i = 0; i < List.Count; i++)

   {

      EditableRootList.RemoveAt(i)

   }

 But I catch an exception: out of arrange. Because when remove a item in EditableRootList, index is changed.

pelinville replied on Wednesday, August 09, 2006

loop backwards
 
for(int i = List.Count -1; i > -1; i--)
{
   List.RemoveAt(i)
 
}
 
 
or something like that

phucphlq replied on Wednesday, August 09, 2006

Sorry, Above code is incorrect

It is here:

 for(int i = 0; i < List.Count; i++)

   {

      EditableRootList.RemoveAt(List[ i ])

   }

Q Johnson replied on Thursday, August 10, 2006

Begin with the largest index item, then the next smallest, next smallest... 

Also, your code removes ALL the items.  You have a list of integers like {2,11,24,26,49}, right?  And you only want to remove items 2, 11, 24, 26, and 49 from the EditableRootList, right?

I don't know C# very well, but I'm going to assume that the way you refer to an item in a list by its listindex is "List(Index).Value".  If that were true, your code should look more like this:

 

  for(int i = List.Count-1; i > -1; i--)

   {

      EditableRootList.RemoveAt(List(i).Value)

   }

 

Fabio replied on Thursday, August 10, 2006

EditableRootList is a template hinerited from  BusinessListBase
You can change your hinerited class from BusinessListBase and public a method that use the implementation of BusinessListBase.
Something like:
public void DeleteAllItems() //<<< your method
{
base.ClearItems();
}

Bye.
Fabio.

Copyright (c) Marimer LLC