您的位置:首页 > 编程语言 > C#

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

2016-11-23 22:43 441 查看
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>集合,然后。。。。

看代码吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐