Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Application ListView , +
hi Everyone ....
 
I want How to remove duplicate items from listview in C#.Net?
 
items have already inserted , now i want to remove duplicate items ?
 
How can i do that ?
 
Thank You....
Posted 9-Dec-12 21:23pm
Edited 9-Dec-12 21:46pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
Use the below method to delete.
List<item> newList = new List<item>();
List<item> itemsToRemove = new List<item>();
foreach(Item item in listView.Items)
{
  if(newList.Contains(item))
  {
      itemsToRemove.Add(item);
  }
  else
      newList.Add(item);
}    
 
//Remove duplicate items here
foreach(Item item in itemsToRemove)
{
  listView.Items.Remove(item);
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The better method is to check for the duplicate entry before inserting to the listbox.
The other way to remove from the items from the list box is by accessing the
ListBox.Items.Remove property.
 
Check this too
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/79d430b5-3797-444e-ab8b-7df4a534d7af[^]
  Permalink  
Comments
krushna chandra jena at 10-Dec-12 2:42am
   
i have already try to check for the duplicate entry before inserting , code was
listView1.FindItemWithText(string)
 
but it falls , thats why i need a function which behaves like Distinct() method [in List Control ] ?
 
Is there any method of that kind?
jibesh at 10-Dec-12 2:45am
   
Please edit your question from ListBox to ListView . we have varieties of controls in .Net :)
well soon find an answer for that...
jibesh at 10-Dec-12 3:15am
   
Unlike the list box, ListView item is not representing one column it might have many columns so its up to you which columns you were checking for duplicate entry.
 
If the Listview has only one column i guess FindItemWithText will work (havent persoanly tried yet)
try checking this
 

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/595ac83b-33aa-4b31-aba9-d0a55ee3e584

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100