ListView exception

  • Thread starter Thread starter yevron2
  • Start date Start date
Y

yevron2

Hello,

When i am trying to remove the last item in a listview:

lstServers.Items.Remove(item);

i get the exception:

A first chance exception of type 'System.ArgumentOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of
valid values.

Does anyone know why that is?

Thanx,
Yael.
 
What is the type of "item"? Is it an integer?

You get this error if you try to access an item with an index that is larger
then the iondex of the last item, for example if you have 5 items in the
listbox then they have indexes 0 to 4, and you will get this error if try to
acces an item using the value 5 as its index.

To remove the last item, try

lstServer.Items.remove(lstServer.Items.Count-1)

Joris
 
item is of type ListViewItem.

The item is taken from the selectedItems, and the list view does remove
it but it throws the exception.
 
I happens when i do it from a pop up menu that i manually poped at the
lstServers_MouseDown.

Thanx for all your help!
 
A first chance exception of type 'System.ArgumentOutOfRangeException'
The item is taken from the selectedItems, and the list view does remove
it but it throws the exception.

It sounds like you have some kind of recurssive behavior going on that
is causing it to try and remove it the first time but fails and when it
tries again it does it, or even vice versa...
 
Back
Top