You're basically looking for a .DistinctBy(..) method, which isn't included in standard .NET but there are implementations, one of which you can find here:
GitHub - morelinq/MoreLINQ: Extensions to LINQ to Objects[
^]
..which will allow you to do this:
List<listviewitem> distinctItems = MyList.DistinctBy(x => x.Name).ToList();
Edit:
If you don't want to include the whole MoreLINQ-project into your solution, use just the following code and copy it into its own C#-source-file:
using System;
using System.Collections.Generic;
namespace LinqExtensions
{
public static class LinqExtensionDistinctBy
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> keys = new HashSet<TKey>();
foreach (TSource item in source)
{
if (keys.Add(keySelector(item)))
{
yield return item;
}
}
}
}
}
Add a
using LinqExtensions; -directive to your files where you want to use this extension method.