Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

CLIPBOARD: How to add several images and strings at once?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steven Van Dyke - 08 Aug 2005 23:19 GMT
Hi,

I have an array of items, each having an image and description. I would like
to programatically copy them all to the clipboard (for pasting into say a
Word document). I've tried the following code, thinking SetData keeps
appending info to the clipboard, but when I paste into Word, I only get the
last description from the last item in my list (no images). What am I doing
wrong here?

private void CopySelectedItemsToClipboard()
       {
           IDataObject ido = new DataObject();

           foreach MyItems myItem in items)
           {
               if (myItem.selected)
               {
                   ido.SetData(DataFormats.Bitmap, myItem.image);
                   ido.SetData(DataFormats.Text, myItem.description);
               }
           }

           Clipboard.SetDataObject(ido, true);

Steve
Michael Phillips, Jr. - 09 Aug 2005 00:04 GMT
You can only store one clipboard format per instance of IDataObject.

That is why you only get the last text object in your loop on to the
clipboard.

Just change your loop to place one clipboard format at a time on to the
clipboard.
Each DataObject instance will hold one clipboard format.

> Hi,
>
[quoted text clipped - 24 lines]
>
> Steve
Atul - 09 Aug 2005 10:24 GMT
When storing to the clipboard in the same format, the new data will
overwrite any existing data.

-Atul, Sky Software  http://www.ssware.com
Shell MegaPack ActiveX & .Net
Drop In Windows Explorer like Shell Browsing GUI controls for your app.

> Hi,
>
[quoted text clipped - 24 lines]
>
> Steve
Oliver Sturm - 09 Aug 2005 10:37 GMT
> I have an array of items, each having an image and description. I would like
> to programatically copy them all to the clipboard (for pasting into say a
> Word document). I've tried the following code, thinking SetData keeps
> appending info to the clipboard, but when I paste into Word, I only get the
> last description from the last item in my list (no images). What am I doing
> wrong here?

You are right about your assumption that SetData appends information (or
rather, data formats). Your code also looks good. What may be your
problem is that while the clipboard can contain multiple data formats at
the same time, only one of them will be accessed by another application.
The reason for this is that the data formats are meant to be different
representations of the same information, NOT different individual pieces
of information.

So when pasting something into Word, there's an algorithm in Word that
looks at the available formats on the clipboard and decides which one of
them to use. The data for this one format is then queried and pasted,
nothing more and nothing less. It's not possible to put more than one
item of data on the clipboard at the same time.

If you'd want to do this for your own application's purposes, it would
be possible to create a class encapsulating the various objects you want
to copy and put that on the clipboard. But obviously Word won't know
about that format, so it won't be any help in your situation. The only
thing you could do is look for a format that Word knows and that might
accomodate multiple data objects at the same time - maybe there's such a
thing because the MS guys felt the need for it at a point :-)

               Oliver Sturm
Signature

omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.