Copy DataGridView contents to clipboard

允我心安 提交于 2019-12-06 18:36:44

问题


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)

But this just pastes nothing.

Any suggestions?


回答1:


Have you added this line?

myDataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;

Take a look at this MSDN article for a working sample.




回答2:


If you use Microsoft Visual Studio You can do it in Design File. Your Gridview ->right Click->Propeties->ClipBoard Copy Mode->EnableWithoutHeaderText



来源:https://stackoverflow.com/questions/1108872/copy-datagridview-contents-to-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!