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?
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?
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