Removing Items in ListView

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

Hi,

I am removing problems but I am having a problem. The code below is
the code being used to remove items from the listview.

ListViewItem oldItem = listViewAllStates.SelectedItems[0];
listViewNextStateSelected.Items.Remove(oldItem);

My problem occurs in the following scenario (example):
Initially ListView empty
Add an item
select first item + remove it
add 2 new items
select first item + remove it.......an error occurs.

I also tried with the SelectedIndeces, and same problem occured. What
I noticed was that the selected index is incorrect. In the same
example the index returned was 2.

Can someone help me out
Thanks in Advance
 
I am removing problems but I am having a problem. The code below is
the code being used to remove items from the listview.

ListViewItem oldItem = listViewAllStates.SelectedItems[0];
listViewNextStateSelected.Items.Remove(oldItem);

My problem occurs in the following scenario (example):
Initially ListView empty
Add an item
select first item + remove it
add 2 new items
select first item + remove it.......an error occurs.

I also tried with the SelectedIndeces, and same problem occured. What
I noticed was that the selected index is incorrect. In the same
example the index returned was 2.

could you post a concise but complete code that reproduces the behaviour you
describe?

Wiktor Zychla
 
Problem solved......I have two listviews, and I was calling the wrong
ListView to get the selected ListViewItem.
 
Back
Top