Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

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
1 Solution
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,


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now