MFC: How to copy/paste from CListView

Dear Experts

In a MFC application with a CListView I would like to add the functionality of being able to select some or all of the fields (with the mouse and selct all by "Ctrl+A"), copy it by pressing "Ctrl+C" and then pasting it, in for instance a Windows Notes document, with the columns delimited by for instance commas. Do any of you have an example of how to do it? I would be very happy!

Thanks very much in advance, Peter
PeterTokeHedenAhlgrenAsked:
Who is Participating?
 
ZoppoCommented:
Hi PeterTokeHedenAhlgren,

unfortunateley I don't have a sample, but I can describe, it's not so difficult.

You just need to copy the text you want to paster otherwhere onto the clipboard. For this you simply iterate through the selected rows and build a string of lines of the comma-seperated sub-/item texts. (BTW: If you use a virtual list control you'll have to fill that string from the scratch).

To do so you can use OpenClipboard, SetClipboardData and CloseClipboard. The clipboard format type to use is CF_TEXT.

Here you can find a detailed description including sample about how to use a clipboard: http://msdn.microsoft.com/en-us/library/ms649016(VS.85).aspx

Hope that helps,

ZOPPO
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.