|
-
Oct 16th, 2008, 08:19 PM
#1
Thread Starter
Hyperactive Member
copy / past datagridview content with column names into Excel
Hello guys !
I would like to copy the content of a datagridview with the column names in the clipboard and then past it into Excel. You may copy/past with datagridviews, but the column names are not copied. Does anybody have an idea how to do this ?
Thanks a lot for any feedback !
Regards,
Fabianus
-
Dec 6th, 2008, 06:58 PM
#2
Re: copy / past datagridview content with column names into Excel
You'd have to see what format the data is copied to the Clipboard in, then construct such a format that included the column headers. Try copying data from a DGV normally and then call Clipboard.GetDataObject to get the copied data as an IDataObject. You can then call GetDataFormats to see what formats the data is available in and GetData to get the data in each of those formats. Once you understand the format of the data, then you can write code to bundle the contents of the DGV, including column headers, into an apropriate format and copy it to the Clipboard yourself.
-
Dec 7th, 2008, 10:47 AM
#3
Thread Starter
Hyperactive Member
Re: copy / past datagridview content with column names into Excel
Hey jmcilhinney !
Thanks a lot - as always your way solved my problem :-)
Here is how I did it :
Code:
Dim ido As IDataObject = Clipboard.GetDataObject
Dim t As String() = ido.GetFormats
If t.Count > 2 Then
Clipboard.SetData("UnicodeText", "nothing" & Chr(9) & "StartMoment" & Chr(9) & "SellTotalWeight" & Chr(9) & "SellPerItemInP" & Chr(9) & "SellPerWeightInKg" & Chr(9) & "SellRecordCount" & Chr(9) & "SellOrderCount" & Chr(9) & "SumTurnoverEurWithVAT" & Chr(9) & "SumTurnoverEurNoVAT" & Chr(9) & "SumProfitEur" & Chr(9) & "MeanPricePerKg" & Chr(9) & "LossTotalWeight" & Chr(9) & "LossPerItemInP" & Chr(9) & "LossPerWeightInKg" & Chr(9) & "LossRecordCount" & Chr(9) & "UnsoldTotalWeight" & Chr(9) & "UnsoldPerItemInP" & Chr(9) & "UnsoldPerWeightInKg" & Chr(9) & "UnsoldRecordCount" & Chr(13) & Chr(10) & ido.GetData(t(3)))
End If
Thanks again for you precious suggestions !
Regards,
Fabianus
-
Jan 5th, 2009, 01:02 PM
#4
Thread Starter
Hyperactive Member
Re: copy / past datagridview content with column names into Excel
Hey jmcilhinney,
I just discovered the "ClipboardCopyMode" property of the DataGridView : simply set it to EnableAlwaysIncludeHeaderText and the column's header is copied, too :-)
See you,
Fabianus
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|