过滤listview的重复项,
如: id name id name
1 abc 1 abc
2 edf 2 edf
3 abc ==>> 4 hhh
4 hhh
5 abc
6 edf 我做的是 WINFORM 程序 具体代码如何编写!找了3天了,没有正确答案,难道这个实现起来这么困难啊!!
如: id name id name
1 abc 1 abc
2 edf 2 edf
3 abc ==>> 4 hhh
4 hhh
5 abc
6 edf 我做的是 WINFORM 程序 具体代码如何编写!找了3天了,没有正确答案,难道这个实现起来这么困难啊!!
2、填充好之后,先按name排序再删除
3、填充之前就过滤掉name重复的项,然后再填充listview(个人倾向于)
delete from table where id not in (select min(id) from table group by name)
select id,name from 表 where 1=1 group by id,name在程序中。先获得一个DataTable。然后FOREACH这个DT。检索重复的。
检索的代码就不写了。这个问题可以有很多种方法去实现它
select * from emp where name in
(select name from emp group by name having count(*)>1)
这样直接查出重复的数据
也就是你上面的:
id name
1 abc
2 edf
4 hhh
就一边判断一边加载数据到listview里 如果名字有重复的话不在添加就OK
直接数据库操作!!
public partial class Form1 : Form
{
int[] saveNum = new int[5] { 1, 2, 3, 4, 5 };
string[] saveString = new string[5] { "abc","edf","abc","hhh","abc" }; public Form1()
{
InitializeComponent(); for (int i = 0; i < saveNum.Length; i++)
{
string[] savedItem = new string[2];
savedItem[0] = saveNum[i].ToString();
savedItem[1] = saveString[i];
//将所有数据存储在列表视图项中
ListViewItem item = new ListViewItem(savedItem);
listView1.Items.Add(item);
}
SearchDunplication();
} public void SearchDunplication()
{
for (int i = 0; i < listView1.Items.Count; i++)
{
for (int j = i + 1; j < listView1.Items.Count; j++)
{
if (listView1.Items[i].SubItems[1].Text == listView1.Items[j].SubItems[1].Text)
{
MessageBox.Show("There found the same text ."+i+":"+j+" "+listView1.Items[i].SubItems[1].Text);
//and then delete the same items from these,but save only one item.
}
}
} }
}做了1个模型,你拿去瞅瞅
直接拿那个源来进行过滤再绑就行了嘛
我是这么做的 但是我只会 listbox 的 contains 方法
用到listview上不行 才来求教的 很多朋友很热心提供了一些思路 我谢谢大家了 思路不是问题的 问题我是新手 我实现不了 所以望高人们可以给出代码 这样直观点,我也可以学习下!还有根多朋友给出的 SQL语句 我开头说了 我做的是 WINFORM
接下来继续等待 高人的出现!!!
z1 = z[s.Next(0, 8)];
for (int i = 1; i <= s.Next(1,8); ++i)
{
if (!listBox1.Items.Contains(z1)) //如果不包含这个项则添加
{
listBox1.Items.Add(z1);
}
else
{
while (listBox1.Items.Contains(z1))//如果包含则重新取
{
z1 = z[s.Next(0, 8)];
}
listBox1.Items.Add(z1);//直到不包含在内,则添加进去
}
}
这个是listbox实现的代码 简单说 我想用listview 控件 代替 listbox 代码该如何改!!