如何从C#.Net中的listView中删除重复项? [英] How to remove duplicate items from listView in C#.Net ?

查看:439
本文介绍了如何从C#.Net中的listView中删除重复项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好....



我想如何从C#.Net中的listview中删除重复的项目?



物品已经插入,现在我想删除重复的物品?



我该怎么办? ?



谢谢....

解决方案





使用以下方法删除。

列表< item> newList =  new  List< item>(); 
列表< item> itemsToRemove = new 列表< item>();
foreach (项目 in listView.Items)
{
if (newList.Contains(item))
{
itemsToRemove.Add(item);
}
else
newList.Add(item);
}

// 在此处删除重复的项目
foreach (项目 in itemsToRemove)
{
listView.Items.Remove (项目);
}


更好的方法是在插入列表框之前检查重复的条目。

另一种方式从列表框中删除项目是通过访问

ListBox.Items.Remove属性。



检查这个

http://social.msdn .microsoft.com / forums / zh-CN / winforms / thread / 79d430b5-3797-444e-ab8b-7df4a534d7af [ ^ ]


http://stackoverflow.com/questions/2096489/c-sharp-removing-items-from-listbox [ ^

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....

解决方案

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);
}


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[^]


http://stackoverflow.com/questions/2096489/c-sharp-removing-items-from-listbox[^]


这篇关于如何从C#.Net中的listView中删除重复项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆