本文介绍了c#将Listview列复制到另一个ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在listview1上有一个c#表单,并且有A,B,C,D,E列。另一种形式是ListView2,它有3列。我想将Listview1上的A,C,D列复制到ListView2。谢谢

Hi I have a c # form on listview1 and have A, B, C, D, E columns. Another form is ListView2, which has 3 columns. I want to copy columns A, C, D on Listview1 to ListView2. Thank you

推荐答案

我认为这不是关于GUI,而是关于数据。尝试处理来自lv1的数据,然后添加到lv2,如下所示。

I think it's not about the GUI, it's about the data. try to cope data from lv1 and then add to lv2 as below.

     List<ListViewItem> tempList = new List<ListViewItem>();

            foreach (ListViewItem lvi in listView1.Items)
            {
                if(lvi.Text=="A"|| lvi.Text == "C"|| lvi.Text == "D")
                {
                    tempList.Add(lvi);
                    listView1.Items.Remove(lvi);
                }
            }

            foreach (ListViewItem lvi in tempList)
            {
                listView2.Items.Add(lvi);
            }

最好的问候,

Bob


这篇关于c#将Listview列复制到另一个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 22:35