Re: Efficient way of removing selected items from a (very) large ListView



Bry, I don't personally know of a way in c# to cycle thru a collection
backwards (but you should be able to do it). (In VB6 [maybe vb.net] you have
a Step -1 so you can decrement backwards) Don't think this will work with a
collection.

Idea: You might be able to cycle (foreach) thru the lv.SelectedIndices
collection and assign the index values to an integer array and then use a
regular for loop and decrement loop control variable.

foreach (int index in lv.SelectedIndices)
{
intArray.Add(index); /* ArrayList or int array ???*/
}

int max = lv.SelectedIndices.count; (or intArray.Count)
for(i = max, 0, i--)
{
lv.Items.RemoveAt(intArray(i)); // Might have to convert object to
int if you use an array list and not a int array.
}

It has been a long time since I really tried to write some C/C++/C# code and
not sure if the syntax of the loop is correct but you get the idea.
Removing the item in reverse order as you suggest would / should only effect
the items at the end of the list and perserve the lower indexed items.

Please let me know if this works.

JerryM


.



Relevant Pages

  • Re: Fridays the thirteenth. (And a little puzzle.)
    ... -- compiler) is the usual method ... int febdays ... -- We're going to go round a loop dealing with each year in turn. ... -- other languages call) ...
    (uk.people.silversurfers)
  • Re: C code is not generating required results.
    ... int main ... the array by the size of an element. ... prevent the user of your program from entering more characters than ... want to loop. ...
    (comp.lang.c)
  • Re: long double versions of functions in gcc under Cygwin
    ... rather than the nearest enclosing one) and a decent exception ... them it doesn't seem like goto usage would be affected ... int typfun() ... Why use a for loop when it is just a while loop in disguise? ...
    (comp.lang.c)
  • Re: enum type int or unsigned int?
    ... that have type int and may appear wherever such are permitted. ... values of all the members of the enumeration. ... "enum" types are declared via the following syntax: ... so the loop will continue to run. ...
    (comp.lang.c)
  • Re: STL - Vector - Normalization ?
    ... there's no time saved in the instructions of the body of the loop. ... > int max; ... and for "two" it calls the two-pass method. ... algorithms min_element etc in the function and did not use functors. ...
    (comp.lang.cpp)