如何清除重复数据C# [英] How to clear duplicate data C#

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

问题描述

当我在列表视图中有项目时,想要创建一个表单来编辑它。在我编辑后,我点击返回旧表格,项目被编辑,但当我再次点击返回表格编辑时,它有旧的和新的数据。



我尝试过:



When I have items in a listview, and want to make a form to edit it. after I edited I click back to old form the items are edited but when I click back to form edit again it has the old one and new data one.

What I have tried:

public static ListView lstView = new ListView();
      // public static ListView lst_View = new ListView();
       private void btnEdit_Click(object sender, EventArgs e)
       {
           if (lstView1.Items.Count > 0)
           {
               frmEdit Frm = new frmEdit();

               ListViewItem itemClone;
               ListView.ListViewItemCollection temp = lstView1.Items;
               foreach (ListViewItem item in temp)
               {
                   itemClone = item.Clone() as ListViewItem;
                   lstView1.Items.Remove(itemClone);
                   lstView.Items.Add(itemClone);

               }


               Frm.Show();

               this.Hide();

           }

推荐答案

很明显,您的旧数据存储在某处并持续到第二形成。您需要清理代码



您还可以使用Set类来维护唯一的项目列表
Clearly your old data is stored somewhere and going through to the second form. You need to clean up your code

You can also use a Set class to maintain a unique list of items


这篇关于如何清除重复数据C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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