views:

1260

answers:

1

I have a C# Windows Form Application with a DataGridView.

Copy & Paste (ctrl-c after selecting the data in the datagrid and ctrl-v in Excel) is working almost fine.

The problem is that the style (such as background color) is not being pasted in Excel, only the cell values. Do I need to change a property somewhere on my datagridview or implement custom code?

Thanks,

A: 

AFAIK the only data grid property that affects clipboard behavior is the "ClipBoardCopyMode" and that pretty much is "use headers or not". Unless I am off base, if you want the formatting to go with it, you are going to have to put it in the clipboard yourself. But to be honest, as a user I wouldn't want the formatting. It drives me nuts when I copy things an then have to reformat them to match the format I'm currently using. I'd much rather paste in the data, and then if I want to format it as displayed, do that. If you are going to roll your own I'd suggest using the Excel Clipboard format so your user can "PasteSpecial" values if they want to. This might give you some ideas: http://www.codeguru.com/vb/gen/vb_misc/samples/article.php/c6393

Oorang