473,386 Members | 1,706 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,386 software developers and data experts.

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 32867
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.com> 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.GetDataObject()
Dim sr As New System.IO.StreamReader(CType
(t.GetData("csv"), System.IO.MemoryStream))

Do Until sr.Peek = -1
row(0) = sr.ReadLine
ds.Tables(0).Rows.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.com>
| Sender: "Faith" <fa***@wwstar.com>
| 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: AcOMPEnLwuvaLw2ZRyivWZ5gJYcj1w==
| Newsgroups: microsoft.public.dotnet.general
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:110924
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| 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
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...
0
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...
2
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)...
1
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
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...
2
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...
3
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...
3
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...
2
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...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
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...

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.