Simon Mourier's Avatar
Simon Mourier's blog (1807 answers on StackOverflow) about Microsoft technologies C#, C/C++, .NET, WinRT, WinUI3, AOT, P/Invoke, COM, Interop, DirectX, Direct2D, Windows, ...
  • 🔎︎ Search
  • Categories
  • Archives
  • About Me
  • controls
  • wpf

How to eradicate duplicate items while adding in Existing WPF ListView

Oct 20, 2015 See the question and my original answer on StackOverflow

You could use the ItemCollection.IndexOf Method like this:

if (lvw1.Items.IndexOf(keyitem) < 0)
{
    // add the object
}

Note this will implicitely use the keyitem object's Equals method, whatever that does. If it's not ok, then you'll have to enumerate the whole collection (using Linq methods for example) for something that suits your needs.

  • SmoBlog © 2010-2026 Simon Mourier. All rights reserved.
  • Privacy & Terms