By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,164 Members | 850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,164 IT Pros & Developers. It's quick & easy.

DataGrid copy/paste from Excel

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.