将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)
但这只是没有任何东西。
But this just pastes nothing.
任何建议?
答
你添加了这行吗?
myDataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
看看这个MSDN文章的工作示例。