Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy DataGridView contents to clipboard

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?

like image 719
Karl Avatar asked Jul 10 '09 10:07

Karl


2 Answers

Have you added this line?

myDataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;

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

like image 95
Magnus Johansson Avatar answered Nov 04 '22 21:11

Magnus Johansson


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

like image 4
Mir Md Faysal Avatar answered Nov 04 '22 21:11

Mir Md Faysal