views:

1226

answers:

1

Hi

I want to copy the contents of a DataGridView and paste in in Excel. I tried

         myDataGrid.SelectAll();
         DataObject dataObj = myDataGrid.GetClipboardContent();
         Clipboard.SetDataObject(dataObj, true)

But this just pastes nothing

Any suggestions?

Thanks

A: 

Have you added this line?

myDataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;

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

Magnus Johansson
No I didn't, thanks
Karl