DIScussion wrote:
> Hi,
> I use -multisel => 2 option in Listbox properties
> to allow multiple selection ehnanced (with Shift, Control, etc.)
> But I can not remove all selected items. I can remove only either
> one item at a time or some of selected items but not all.
> For example If I select item 1,3,and 4,
> items 1 and 4 are deleted, but not 3.
> There is either a bug or there si something wrong in my program.
there is a misunderstanding ;-)
items are indexed by their progressive number of appearance (just
like elements in an array).
so if you have 5 items, when you remove, let's say, item n. 2,
your previous item n. 3 becomes the new n. 2, n. 4 -> 3,
and so on.
a workaround for this is to sort the list of selected items in
descending order, removing first the higher then the lower ones:
sub Remove_Click {
foreach $i (
sort { $b <=> $a }
$List2->SelectedItems()
) {
$List2->RemoveItem($i);
print "Chosen $i,";
}
print "\n";
return 1;
}
I'll fix SelectedItems() to return items already sorted
in descending order, so there'll be no confusion :-)
cheers,
Aldo