zoukankan      html  css  js  c++  java
  • 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>集合,然后。。。。

    看代码吧。

  • 相关阅读:
    Python+MySQL学习笔记(一)
    MySQL的基本操作
    2016.08.15
    使用vue为image的src动态赋值
    json对象与json字符串的转化
    js三元运算符
    uniapp vue中的短信验证码
    设计模式
    回调函数
    自定义注解
  • 原文地址:https://www.cnblogs.com/testsec/p/6095846.html
Copyright © 2011-2022 走看看