By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,050 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,050 IT Pros & Developers. It's quick & easy.

ListView Item Uniqueness and ContainsKey Method

P: n/a
I have the following requirement:
A form with 2 ListViews. lvSource which contains a list of items that the
user can select from and lvTarget where the selected item(s) end up. Items
should never be removed from lvSource, yet no item can be added to lvTarget
more then once.

To ensure the last requirement I set the .Name property on each ListViewItem
as it is created in lvSource to be that entity's unique ID. Then I call
lvTarget.Items.ContainsKey when the user tries to add the item to ensure no
duplicated in lvTarget. However, as we know, the same ListViewItem can not
exist in 2 different ListViews, so I cannot simply add the ListViewItem to
lvTarget, but I must clone it first. However, the cloned item has a
different name then the initial item and therefore ContainsKey always returns
false and the item is always added.

Short of storing the unique ID in the tag and iterating through all the
records in lvTarget to ensure uniqueness, is there a way to solve this
problem?
Sep 28 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.