• C# listview控件右击导出数据到txt文本


    private void 导出成功点击ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (listCount.Items.Count == 0)
                {
                    MessageBox.Show("列表为空!");
                }
                else {
                    List<string> list = new List<string>();
                    foreach (ListViewItem item in listCount.Items)
                    {
                        string temp = item.SubItems[2].Text;
                        list.Add(temp);
                    }
                    Thread thexp = new Thread(() => export(list)) { IsBackground = true };
                    thexp.Start();
                }
            }
            private void export(List<string> list)
            {
                string path = AppDomain.CurrentDomain.BaseDirectory + "url_" + Guid.NewGuid().ToString() + ".txt";
                StringBuilder sb = new StringBuilder();
                foreach (string tel in list)
                {
                    sb.AppendLine(tel);
                }
                System.IO.File.WriteAllText(path, sb.ToString(), Encoding.UTF8);
                txtmsg.BeginInvoke(new Action(() => {
                    string temp = "文件导出成功!文件地址:" + path;
                    txtmsg.AppendText(temp.SetLog());
                }));
            }

    自己写的,并且测试可用,才发上来的!!!!

    就是循环listview.items,然后,装到一个list<string>集合,然后。。。。

    看代码吧。

  • 相关阅读:
    图解设计模式-Visitor模式
    图解设计模式-Decorator模式
    图解设计模式-Strategy模式
    图解设计模式-Bridge模式
    HashMap源码
    LinkedList源码
    Vector源码
    ArrayList源码
    图解设计模式-Abstract Factory模式
    图解设计模式-Builder模式
  • 原文地址:https://www.cnblogs.com/testsec/p/6095846.html
Copyright © 2020-2023  润新知