473,791 Members | 2,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Comm aSeparatedValue 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.Comm aSeparatedValue 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.SetDa taObject
("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.Comm aSeparatedValue 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 2005

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

Similar topics

0
2237
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 the clipboard is corrupted. For example, a U with double accent ( byte code x'FB' ) is replaced by a question mark in my txtEdit.Text after a Paste operation. It seems that the Clipboard.GetText() is changing the data. How is it possible to...
8
11478
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 database, and I need the data to be laid out in a tabular format, and set out in a specific way. At the current point in time, I am copy/pasting the raw text from the database into a table layout in InDesign. What I was thinking is that if I could...
5
4079
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 + C -- Go to Word and look under Edit > Paste Special -- Note there is a source reference and an option to paste the chart as a
6
1612
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 other application both ways. Is there any way to solve this problem, I have noticed that some application have more than 1 clipboard are these also system clipboard Thank you in advance,
0
3255
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 were to copy the image from Ms- Word and "Paste as New Image" in Photo Editor, I got the resolution 2288 x 1712. If I used the code below, I got the image size of 720 x 538 stored in PreviewBitmap variable. Why is the size of the picture...
4
6608
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 clipboard? I tried the code below, but it didn't seem to tell me if the clipboard was empty. If Clipboard.GetDataObject() Is Nothing Then MessageBox.Show("Clipboard is empty") Else Dim txtdata As IDataObject = Clipboard.GetDataObject() If...
4
4219
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 how to get a string that is in the clipboard into a variable in the macro. I tried this: Dim x as string = DTE.ActiveDocument.Selection.Paste() thinking it would "paste" the clipboard into the string variable X, but it just pasted the
0
1908
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 the clipboard so it can be pasted into this other application. My solution is working fine with all applications (mspaint, word, wordpad) except the one I need it to work with. I've contacted the vendor of the application, but I haven't been able...
7
3852
by: Newbie | last post by:
How do I clear the clipboard in VB.NET 2003? TIA Newbie
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.