Click here to Skip to main content
13,591,515 members
Rate this:
Please Sign up or sign in to vote.
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 20:23pm
Updated 9-Dec-12 20:46pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


Use the below method to delete.
List<item> newList = new List<item>();
List<item> itemsToRemove = new List<item>();
foreach(Item item in listView.Items)

//Remove duplicate items here
foreach(Item item in itemsToRemove)
Rate this: bad
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[^]
krushna chandra jena 10-Dec-12 2:42am
i have already try to check for the duplicate entry before inserting , code was

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 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 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
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

The following will hide duplicates, in this case TestName and it's assiciated checkbox as the Listview is Data Bound.

protected void lvConditionTests_ItemDataBound(object sender, ListViewItemEventArgs e)
if (e.Item.ItemType == ListViewItemType.DataItem)
CheckBox cbIConditionDelete = (CheckBox)e.Item.FindControl("cbIConditionDelete");
cbIConditionDelete.CheckedChanged += new EventHandler(cbIConditionDelete_CheckedChanged);

CheckBox cbITestDelete = (CheckBox)e.Item.FindControl("cbITestDelete");
cbITestDelete.CheckedChanged += new EventHandler(cbITestDelete_CheckedChanged);

Label lblITestName = (Label)e.Item.FindControl("lblITestName");
txtTestName = lblITestName.Text;
if (txtTestName == txtPrevTestName && intCtr > 0)
//Hide the Text Name and CheckBox
lblITestName.Visible = false;
cbITestDelete.Visible = false;
txtPrevTestName = txtTestName;


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.180618.1 | Last Updated 20 Jan 2015
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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