471,570 Members | 940 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Removing Items in ListView

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

Jan 5 '06 #1
2 1846
> 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

Jan 5 '06 #2
Problem solved......I have two listviews, and I was calling the wrong
ListView to get the selected ListViewItem.

Jan 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Visual Systems AB \(Martin Arvidsson\) | last post: by
6 posts views Thread by Nick | last post: by
1 post views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.