ListView 复制到剪切板

时间:2023-11-24 09:33:38
  private void 导出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetText(GetListView(listViewData));
} public string GetListView(ListView listview)
{
string outStr = "";
string single;
for (int i = ; i < listview.Items.Count; i++)
{
single = "";
if (i == )
{
for (var j = ; j < listview.Columns.Count; j++)
{
single = single + listview.Columns[j].Text + "\t";
}
single = single.Substring(, single.Length - ) + "\r\n";
}
for (var j = ; j < listview.Columns.Count; j++)
{
single = single + listview.Items[i].SubItems[j].Text.Replace("\n", "") + "\t";
}
outStr = outStr + single.Substring(, single.Length - ) + "\r\n";
}
return outStr;
}