473,699 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid copy/paste from Excel

Hello.
I need to take a column from Excel(unknown amount of rows)
that will be selected by the user and copy those cells.
Then I will need to paste those cells into the first
column in a Data Grid (system.windows .forms).
Basically, the user receives a list of clientIDs from a
client as an email attachment in Excel listed like:
1234 ABC Company
234 DEF Company
348 GHI Company
....and so on
The user copies the first column of clientIDs and will
need to paste them into a data grid in a program. Is
there a way to do this??

Thanks so much for your help!
Faith
Jul 21 '05 #1
3 32942
Hi,

You should bind the grid to a data source (DataTable, for example). Then,
react on Ctrl-V shortcut (as well as Edit->Paste etc. etc.) and upon the
user attempting to paste the data,
examine what's available on the clipboard, parse the pasted data if
necessary and populate the corresponding column of the bound data table with
the parsed client ID values.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Faith" <fa***@wwstar.c om> wrote in message
news:06******** *************** *****@phx.gbl.. .
Hello.
I need to take a column from Excel(unknown amount of rows)
that will be selected by the user and copy those cells.
Then I will need to paste those cells into the first
column in a Data Grid (system.windows .forms).
Basically, the user receives a list of clientIDs from a
client as an email attachment in Excel listed like:
1234 ABC Company
234 DEF Company
348 GHI Company
...and so on
The user copies the first column of clientIDs and will
need to paste them into a data grid in a program. Is
there a way to do this??

Thanks so much for your help!
Faith


Jul 21 '05 #2
Faith,

This is not the most stable sample, you will want to do a
lot of checking with the data before you place it in the
grid, but you can see where it is going

Dim t As IDataObject
Dim row(0) As String

t = Clipboard.GetDa taObject()
Dim sr As New System.IO.Strea mReader(CType
(t.GetData("csv "), System.IO.Memor yStream))

Do Until sr.Peek = -1
row(0) = sr.ReadLine
ds.Tables(0).Ro ws.Add(row)
Loop

kirk
-----Original Message-----
Hello.
I need to take a column from Excel(unknown amount of rows)that will be selected by the user and copy those cells.
Then I will need to paste those cells into the first
column in a Data Grid (system.windows .forms).
Basically, the user receives a list of clientIDs from a
client as an email attachment in Excel listed like:
1234 ABC Company
234 DEF Company
348 GHI Company
....and so on
The user copies the first column of clientIDs and will
need to paste them into a data grid in a program. Is
there a way to do this??

Thanks so much for your help!
Faith
.

Jul 21 '05 #3
Hi Faith,

If you want to copy a column in an Excel worksheet to the datagrid, you can
try using OleDB to achieve this. Here's a KB article for you to see how to
connect to an Excel file using OleDB.

http://support.microsoft.com/default...b;en-us;311731

Based on the KB, you have to define a name which indicates the column you
want to copy in the Excel file. This can be done by VBA. If you don't want
the blank cells to be copied, just add WHERE columnname <> NULL after the
SELECT clause.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Faith" <fa***@wwstar.c om>
| Sender: "Faith" <fa***@wwstar.c om>
| Subject: DataGrid copy/paste from Excel
| Date: Mon, 6 Oct 2003 12:01:46 -0700
| Lines: 17
| Message-ID: <06************ *************** *@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOMPEnLwuvaLw2 ZRyivWZ5gJYcj1w ==
| Newsgroups: microsoft.publi c.dotnet.genera l
| Path: cpmsftngxa06.ph x.gbl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:110924
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.publi c.dotnet.genera l
|
| Hello.
| I need to take a column from Excel(unknown amount of rows)
| that will be selected by the user and copy those cells.
| Then I will need to paste those cells into the first
| column in a Data Grid (system.windows .forms).
| Basically, the user receives a list of clientIDs from a
| client as an email attachment in Excel listed like:
| 1234 ABC Company
| 234 DEF Company
| 348 GHI Company
| ...and so on
| The user copies the first column of clientIDs and will
| need to paste them into a data grid in a program. Is
| there a way to do this??
|
| Thanks so much for your help!
| Faith
|

Jul 21 '05 #4

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

Similar topics

3
9552
by: cv | last post by:
Hi all, I have to copy two set of data from 2 files(notepad/excel) say, products and their corresponding prices to list/textarea/table. I should be able to retrieve the product and corresponding price information from the control(list/textarea/table). Which is the best way? Quite urgent.. pls let me know. TIA, cv
0
1419
by: Mr Marsh | last post by:
Hello, I'll try and provide as much information as I can about the problem/challenge I'm facing. I have found similar postings to my enquiry but they don't really hit the nail on the head. I am writing an application and part of that app shows information in a datagrid - I am currently able to save that out to an excel file on the clients machine. I would like to be able to take that a little further. The data is always in a...
2
35221
by: Mansi | last post by:
I'm trying to automate excel from c#. One of the things I need to do is to copy/paste/insert rows in excel via c# code. I tried to do the following: 1) Select a row in excel (a12 to k12) 2) Insert a row. 3) copy contents of a12 to k12. 4) Paste these contents to new row. The "Record Macro" function returns the following code:
1
1636
by: Eddy Balan | last post by:
Hi. Please help me....... I would like to copy the datagrid contents to clipboard and then to paste it into Excel but I can't make a multiple selection. Eddy
2
2862
by: TM | last post by:
I have an Excel sheet where I setup my needed formatting, page settings, ect, and would like to take my data from a datagrid and paste it into the excel file and print the excel file. Any idea how to do this ? But. my other problem is my excel sheet if setup for two columns of formatting, and I would like to paste the data into column 1 until it gets to cell 30, then if there is more than 30 records, paste them into the second column...
2
10720
by: Kevin Hodgson | last post by:
I have a standard .NET Datagrid (Databound to a SQL Dataset), and I need to select all rows of the datagrid when a button is clicked, to allow a user to copy the data, and then paste it into Excel or another application. They need to be able to do this because the application is running on a Terminal Server in Application Server Mode, and they need to copy the data to an Excel worksheet on their local computer. I can do this manually by...
3
739
by: Faith | last post by:
Hello. I need to take a column from Excel(unknown amount of rows) that will be selected by the user and copy those cells. Then I will need to paste those cells into the first column in a Data Grid (system.windows.forms). Basically, the user receives a list of clientIDs from a client as an email attachment in Excel listed like: 1234 ABC Company 234 DEF Company 348 GHI Company
3
4315
by: charmagne | last post by:
I have completed my development using a Datagrid in VB6. I need the users to be able to select all of the rows and columns (that were returned and displayed in the grid) so they can copy them to excel. At present, I can select each column by holding down the shift key to get all the columns, but I can not get the data to copy and paste into excel. Please help... thx
2
7620
by: deve8ore | last post by:
Hello, I'm working with Adobe Reader 8.0, working on a project for work, so not allowed to download any other software/ freeware. We receive PDF files frequently with about 20 sheets. I'd like to copy these 20 sheets at one time and just paste them into an Excel spreadsheet (one sheet). Nothing fancy, no elaborate formatting, I would just like the picture of the PDF sheets in Excel. I can manually copy one sheet and paste onto the...
0
8687
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
8617
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,...
0
9174
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8884
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...
0
5875
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
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
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
2347
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.