ListView 复制到剪切板

  private void 导出ToolStripMenuItem_Click(object sender, EventArgs e)
        {     
            Clipboard.SetText(GetListView(listViewData));
        }

        public string GetListView(ListView listview)
        {
            string outStr = "";
            string single;
            for (int i = 0; i < listview.Items.Count; i++)
            {
                single = "";
                if (i == 0)
                {
                    for (var j = 1; j < listview.Columns.Count; j++)
                    {
                        single = single + listview.Columns[j].Text + "\t";
                    }
                    single = single.Substring(0, single.Length - 1) + "\r\n";
                }
                for (var j = 1; j < listview.Columns.Count; j++)
                {
                    single = single + listview.Items[i].SubItems[j].Text.Replace("\n", "") + "\t";
                }
                outStr = outStr + single.Substring(0, single.Length - 1) + "\r\n";
            }
            return outStr;
        }

 

posted @ 2015-04-27 17:19  奇风★逍遥  阅读(832)  评论(0编辑  收藏  举报