| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 765 人关注过本帖, 1 人收藏
标题:将ListView中的信息复制到另一窗口的ListView中
取消只看楼主 加入收藏
Sephirose
Rank: 1
来 自:四川-乐山
等 级:新手上路
帖 子:51
专家分:0
注 册:2013-3-26
结帖率:55.56%
收藏(1)
已结贴  问题点数:16 回复次数:2 
将ListView中的信息复制到另一窗口的ListView中
两个窗口form1和form2,各有一个ListView控件,form2上有一个Button按键,想要实现的功能是点击Button后将该页面的ListView控件中的内容显示到form1中的ListView中,该怎么实现啊,我自己想的是用foreach遍历整个ListView控件中的内容,再将其值传递过去,但是显示的是“无法将类型string[]为System.Windows.Forms.ListViewItem”,
form2
public string[] ord;

 private void button1_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.Items)
            {
                string[] ord = new string[] { Convert.ToString(item) };
            }
            this.Close();
        }

form1
public Form1 od = null;

 private void Form_Load(object sender, EventArgs e)
        {
            this.listView1.Items.AddRange(new ListViewItem[] { od.ord });
        }
搜索更多相关主题的帖子: private 
2013-03-30 18:35
Sephirose
Rank: 1
来 自:四川-乐山
等 级:新手上路
帖 子:51
专家分:0
注 册:2013-3-26
收藏
得分:0 
回复 2楼 yhlvht
尝试着修改了,系统可以运行,可是不显示内容啊
form1
public Form2 od = null;

private void Form_Load(object sender, EventArgs e)
        {
             ListViewItem[] lv = od.ord.ToArray();   
            this.listView1.Items.AddRange(lv);   
        }

form2
public List<ListViewItem> ord;

 private void button1_Click(object sender, EventArgs e)
        {
            ord = new List<ListViewItem>();
            foreach (ListViewItem item in listView1.Items)
            {
                ord.Add((ListViewItem)(item.Clone()));
            }
            this.Close();
            Sell ss = new Sell();
            ss.Show();
            this.Hide();
        }
2013-04-01 23:25
Sephirose
Rank: 1
来 自:四川-乐山
等 级:新手上路
帖 子:51
专家分:0
注 册:2013-3-26
收藏
得分:0 
回复 4楼 yhlvht
是这样子的么
private void button1_Click(object sender, EventArgs e)
        {
            Sell ss = new Sell();
            
            ord = new List<ListViewItem>();
            ss.od = this;
            foreach (ListViewItem item in listView1.Items)
            {
                this.ord.Add((ListViewItem)(item.Clone()));
            }
            ss.Show();
            this.Close();
        }
2013-04-02 14:05
快速回复:将ListView中的信息复制到另一窗口的ListView中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015683 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved