views:

121

answers:

2

Hello,

I have a listview in which a user can browse for assemblies, the problem is that the user can add the same entry from the dialogbox. This is useless and does not account for anything, so how can i get rid of this?

My question is, how does one compare with the item in the listview so that it does rule this out. Yes! There has already been a question about this but neither of the answers helped.

I just need guidance, as I can't find many good examples on the net.

Thanks

A: 

I would basically keep what you already have but instead of throwing an error I would just not add it and move the existing item to the top (or bottom) of the ListBox. It's not really an error; it's more like they can't find what they were looking for so they added a new one.

Austin Salonen
+2  A: 

You can use LINQ:

string newName = searcha.GetName().Name;
if (!assemblyView.Items.Cast<ListViewItem>().Any(lvi => lvi.Text == newName))
SLaks
Hello, Your answer worked fine! Its just not a way i'm particularly familiar with... Any other way of doing it?
MW
Yes; you could manually loop through the items and check whether there is a matching item. It would require three times more code and the intent would be less clear.
SLaks