将DataGridView内容复制到剪贴板 [英] Copy DataGridView contents to clipboard

查看:426
本文介绍了将DataGridView内容复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想复制DataGridView的内容并将其粘贴到Excel中。我试过:

I want to copy the contents of a DataGridView and paste it in Excel. I tried:

myDataGrid.SelectAll();
DataObject dataObj = myDataGrid.GetClipboardContent();
Clipboard.SetDataObject(dataObj, true)

但这只是不粘贴。

有没有建议?

推荐答案



Have you added this line?

myDataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;

查看此MSDN文章的工作示例。

这篇关于将DataGridView内容复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆