hello, i am using the item selection changed property inorder to control the items in listview,when the user selects first any item every thing goes well but when he changes selection it gives this exception :
System.ArgumentOutOfRangeException was unhandled
Message=InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
I am using this to get selected items:Items_list.SelectedItems[0].SubItems[2].Text;
I have noticed that at the moment i change selection the selected items count is 0 so what to do?

You might be running into the problem during postback when the page is creating the listview again during the page load. Then once the event handler is called for the seletion change, you are requesting index[0] which doesn't exist yet since no one has been given the chance to select anything in your control. Try placing a validation check for the selected item count to see if it is greater than 0 before getting the items from selected items. If that still doesn't work, please post your code for further review.


thank u that worked greatly!! it's the first time i solve a problem using daniweb :)

This question has already been answered. Start a new discussion instead.