473,394 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

c# grid clipboard question

Hello,

First, I appologize for the length but I want to get all the facts
down so as not to waste any time :)
I'm trying to allow the user of my C# app to copy a DataGrid full of
double values to the clipboard (via ctrl-C, edit->copy, etc).
They can then paste these values wherever (but in particular, excel).

I've searched the web fairly exhaustively and cannot find an answer to
this. Every time someone asks, somone answers with the link I'm about
to post and that's the end of the thread. So either I'm doing
something wrong and the code in the link below works for everyone else
that has asked, or they all gave up in frustration. Supposedly one
can put a DataObject on the clipboard with a
DataFormat.CommaSeparatedValue type. There is example code to do this
at http://www.syncfusion.com/FAQ/WinFor...c98c.asp#q899q but it
does not seem to work for me. Can anyone confirm this? I'm running
win XP, excel 2002 sp-2 and using VS .NET. All I did was create a
simple window with 2 buttons (copy, paste) that call the two c#
functions from that web page. The *only* modificiation I made was to
write the results to a messageBox rather than console in the paste
function.

The results of my efforts were that:

1) If I press the copy button, then the paste button, I get a null
reference exception when creating the streamReader. This means that a
DataObject *is* getting on the clipboard and it *is* of type
DataFormat.CommaSeparatedValue but that when I try to GetData () it
gives back null. This seems to be confirmed by going to excel and
trying to paste. It allows paste (there is data on the clipboard) but
when I try to paste it gives me a MessageBox with "Excel cannot paste
this data". When doing a "paste special" it allows to me to select
which clipboard data to paste and it shows a "CSV" type dataObject,
but again gives the "cannot paste" message. This leads me to beleive
that there is a problem in the function that copies data to the
clipboard.

2) If I copy a selection of data IN excel, then press the paste button
on my test app, it gets and shows the data correctly, leading me to
beleive that the paste function is working semi-correctly (it does not
check for/catch the null reference when data is bad as in (1) above,
but no biggie, can fix that). Again, this leads me to think the
problem is in the copy function.

3) I posted the data to the clipboard as a comma-separated string,
with newlines between the rows, I just called Clipboard.SetDataObject
("1,2,3\n4,5,6");. Excel can then paste this data and reads the
newline correctly for rows, but does not separate the values on commas
into columns. If I change the commas to tabs, then it works
correctly. I discovered this is due to the setting in the Data->Text
to Columns options for excel. If you do a text-to-columns operation
with TAB as the delimiter, then it will correctly handle tabbed data
on the clipboard, but not comma data and vice-versa. So, I can get my
data into excel if I have to, though the user might have to run
text-to-columns on it if their text-to-columns delimiter was different
than the one I chose when they paste the data. This is of course
non-optimal since I should just be able to tell excel that the
clipboard data is in CSV format via DataFormat.CommaSeparatedValue and
have it work no matter what the user's delimiter for text-to-column
ops is.

Has anyone made this CSV on the clipboard thing work? am I way off
base? Do I have to live with option 3 above?

Thanks in advance,
Chris
Nov 16 '05 #1
0 1989

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: xyz | last post by:
I have a menu item to handle clipboard actions (cut, copy, paste). When I paste text that I copied from a Hungarian web page, the display looks normal on my RichTextBox, but the text retrieved from...
8
by: LG | last post by:
Just have a question with regards to the clipboard, and how to read what other applications (Adobe InDesignCS) place in the clipboard. I am currently in the process of creating a booklet from a...
5
by: TC | last post by:
Hello, Here is what I'm trying to do: -- Make sure both MS Excel and MS Word are running -- Create an Excel chart -- Save the Excel file -- Copy the Excel chart onto the clipboard using Ctrl...
6
by: S Shulman | last post by:
Hi I want to write some VB code that copies to the clipboard then pastes it later, however the Clipboard is a system device that is shared between all applications and that may interfere with...
0
by: P N | last post by:
Hi all, I have question about copying picture from MS-Word into the Clipboard and then copy from the Clipboard into the bitmap variable within C#. The original image size is 2288 x 1712. If I...
4
by: Joshua Campbell | last post by:
I am working on an application that needs to parse out data that has been copied into the clipboard. My first questions are how can I detect if the clipboard is empty, and how can I empty the...
4
by: JohnR | last post by:
Hi all, I'm finally sick and tired of manually generating get/set properties for each private variable in a class so I'm trying to create a macro to do it. I'm stuck because I can't figure out...
0
by: James Russo | last post by:
Hello, I have an application which requires an image to be retrived from the clipboard. So, I am writting a quick C# windows application to take images from a webcam and store a single frame on...
7
by: Newbie | last post by:
How do I clear the clipboard in VB.NET 2003? TIA Newbie
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.