The way we do this is to loop round each selected row and cell in the grid,
and append the cell contents to a single long string. After each cell we add
either a comma or tab (user preference) and at the end of each line a
newline character is added. Basically we build a kind of comma-seperated
list. Finally we write it to the clipboard with
Clipboard.SetDataObject(TableText). We add caption headers in the same way.

Gary Leighton
-----Original Message-----
From: Saye, Robert [mailto:[EMAIL PROTECTED]]
Sent: 26 November 2002 18:57
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] FW: [DOTNET-WINFORMS] DataGrid and the
clipboard how to? (No Answer)


        Hi all I couldn't get an answer on the WinForms list,

    To make this simple, lets say I have a data grid with 2 columns 1 of
text and 1 with integers, this grid has 10 rows. How would I go about adding
the functionality of copy and paste to an external application (i.e. Excel)?
For instance, how would I copy 3 rows that I have highlighted? Also can you
do the same with an entire column? There isn't much about this anywhere,
Petzold avoided it in his book as did Balena in "Programming Visual Basic
.Net". A search on Google produced one newsgroup question answered as
follows? I think a small code snippet would have been a little more helpful.

****************Quote*****************************
Dave,

I'm afraid you need to manually format the data in the underlying datasource
of the
DataGrid
<http://www.dotnet247.com/247reference/System/Web/UI/WebControls/DataGrid.as
px>  before using the technique to copy it to the clipboard.

Thanks,

Peter Wu
Microsoft Corporation

*************** End Quote ************************************

Thank You,

Robert

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.


KSS Ltd
A division of Knowledge Support Systems Group plc
Seventh Floor  St James's Buildings  79 Oxford Street  Manchester  M1 6SS  England
Company Registration Number 2800886 (Limited) 3449594 (plc)
Tel: +44 (0) 161 228 0040       Fax: +44 (0) 161 236 6305
mailto:[EMAIL PROTECTED]            http://www.kssg.com


The information in this Internet email is confidential and may be legally privileged. 
It is intended solely for the addressee(s). Access to this Internet email by anyone 
else is unauthorised.

If you are not the intended recipient, any disclosure, copying, distribution or any 
action taken or omitted to be taken in reliance on it, is prohibited and may be 
unlawful. When addressed to our clients any opinions or advice contained in this 
Internet email are subject to the terms and conditions expressed in the governing 
engagement letter or contract.

This email message and any attached files have been scanned for the presence of 
computer viruses.  However you are advised that you open any attachments at your own 
risk.


You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to