当前位置:编程学习 > C#/ASP.NET >>

listview过滤重复

过滤listview的重复项,
如: id     name                  id     name
     1       abc                   1      abc
     2       edf                   2      edf
     3       abc        ==>>       4      hhh
     4       hhh                   
     5       abc
     6       edf


行数几千到几万, 需要考虑算法的效率,大家有什么思路, 。。。


--------------------编程问答-------------------- 针对listview的数据源过滤呀,数据源是什么类型? --------------------编程问答-------------------- 不知道有没有什么效率好的方法.

不过我想的方法是

循环第一个表
   再循环第二个表
     如果第一个表的数据=第二个表的数据
     跳出本循环
     否则  第一个表的数据添加到第二个表中


刚刚从网上找来的

Dim RngR As Range
   Set rng = Selection.SpecialCells(xlCellTypeConstants, 1)
   Set DicTmp = CreateObject("Scripting.Dictionary")
   For Each RngR In rng
      If Not DicTmp.exists(RngR.Value) Then
         DicTmp.Add RngR.Value, Empty
      End If
   Next RngR

   Me.ListBox1.List = DicTmp.Keys
   Set rng = Nothing
   Set DicTmp = Nothing


--------------------编程问答-------------------- HashTable
一项以项往hashtable中读   用hashtable.ContainsKey判断是否存在于hash表中  
不存在则Add之..... --------------------编程问答-------------------- 这里给你个例子,希望能帮你.
Dim itmx As ListItem
Set itmx = SearchUserLV.FindItem("要查找的字符串", 1, , 0) '判断是否有重复,如果没有,插入listview
If itmx Is Nothing Then
    Listview1.ListItems.Add , , Listview1.ListItems.Count + 1   '序号  
    Listview1.ListItems(Listview1.ListItems.Count).SubItems(1) = "要查找的字符串"
    Listview1.ListItems(Listview1.ListItems.Count).SubItems(2) = "其他字符串"
    ...
End If
--------------------编程问答-------------------- 这里给你个例子,希望能帮你. 
Dim itmx As ListItem 
Set itmx = Listview1.FindItem("要查找的字符串", 1, , 0) '判断是否有重复,如果没有,插入listview 
If itmx Is Nothing Then 
    Listview1.ListItems.Add , , Listview1.ListItems.Count + 1  '序号  
    Listview1.ListItems(Listview1.ListItems.Count).SubItems(1) = "要查找的字符串" 
    Listview1.ListItems(Listview1.ListItems.Count).SubItems(2) = "其他字符串" 
    ... 
End If 
--------------------编程问答-------------------- Set itmx = SearchUserLV.FindItem("要查找的字符串", 1, , 0) '判断是否有重复,如果没有,插入listview 
改为:
Set itmx = Listview1.FindItem("要查找的字符串", 1, , 0) '判断是否有重复,如果没有,插入listview  --------------------编程问答-------------------- 学习 --------------------编程问答-------------------- 我也有同样的问题 我做的是winform  想要实现 楼主一样的 效果,具体C#代码如何 编写?我找了3天了
没有找到答案。看来这个问题不太好解决吧!! --------------------编程问答--------------------
delete from table where id not in (select min(id) from table group by name)
--------------------编程问答--------------------
引用 3 楼 sssskkyy 的回复:
HashTable 
一项以项往hashtable中读  用hashtable.ContainsKey判断是否存在于hash表中  
不存在则Add之.....


正解 --------------------编程问答--------------------
引用 9 楼 wackyboy 的回复:
SQL codedelete from table where id not in (select min(id) from table group by name)


不好意思 我没说清楚 我做的是 winform  --------------------编程问答--------------------
引用 10 楼 kuaiyiyijian 的回复:
引用 3 楼 sssskkyy 的回复:
HashTable 
一项以项往hashtable中读  用hashtable.ContainsKey判断是否存在于hash表中  
不存在则Add之..... 
 

正解


你等于没说!! --------------------编程问答-------------------- 哈希表的检索速度 很好 用哈希表表看看 --------------------编程问答-------------------- 2楼的写法是C#的语言吗,感觉像ASP的写法呢!
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,