Hello!
I have a problem with verifying if a certain value is added to a ListView. The items are created with this code:
UltraListViewItem item = new UltraListViewItem(name, new UltraListViewSubItem[ { new UltraListViewSubItem(size, null) }, null);//size is a number item.Key = name;//name is a string item.Value = name; //Control if an item with the same name already exist
if (ultraListViewDocumenti.Items.Contains(name)) { MessageBox.Show("Already in list!"); return; } //Else it is not on the listview so add it to the collection ultraListViewDocumenti.Items.Add(item);
The problem is that it does not enter on the if block and as a result i get an ArgumentException that say "The element is already added"
Any idea how to fix this?
Thank you.
thank you
Contains does a reference comparison on each object in the collection, what you want to use is the Exists method, which does a string comparison of the keys.