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?
Have you added this line?
myDataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
Take a look at this MSDN article for a working sample.
If you use Microsoft Visual Studio You can do it in Design File. Your Gridview ->right Click->Propeties->ClipBoard Copy Mode->EnableWithoutHeaderText
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With