473,324 Members | 2,239 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,324 software developers and data experts.

Copying a set of rows from clipboard in Excel sheet to Datagridview

Hi,

I have a DatagridView in windows form.It has got a column which has some names that are populated from master table in database.Now i need to copy a set of data against these names.

I tried to populate data to the first column from database and then tried to copy excel sheet data against each name but some exceptions are coming.It says "cannot programmaticaly add rows while using data bind".

This is the code that i used for copying excel to grid.Plz help.....

DataRow row = null;
Array colValues = null;
string excelRow = null;
DataTable excelTable = null;
IDataObject clipboardData = null;
excelTable = new DataTable("Excel");

if (Clipboard.ContainsData(DataFormats.CommaSeparated Value))

{

clipboardData = Clipboard.GetDataObject();

using (StreamReader reader = new StreamReader((Stream)(clipboardData.GetData(DataFo rmats.CommaSeparatedValue))))

{

while (reader.Peek() > 0)

{

excelRow = reader.ReadLine();

colValues = excelRow.Split(',');

if (! (excelTable.Columns.Count > 0))

{

for (int i = 0; i <= colValues.GetUpperBound(0); i++)

{

excelTable.Columns.Add();

}

}

row = excelTable.NewRow();

for (int i = 0; i <= colValues.GetUpperBound(0); i++)

{

row[i] = colValues.GetValue(i);

}

excelTable.Rows.Add(row);

}

}

}
uxGrid.DataSource = excelTable;
Apr 5 '07 #1
0 1980

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: (Pete Cresswell) | last post by:
I see this coming on a develpment effort that may materialize shortly. These guys don't want to mess around with automated imports from text feeds BC in the past they've had too many problems...
1
by: ʹÃûÑï | last post by:
hi: purpose: clone the firest sheet in Excel.xls into excel2.xls here is my code it well done in winform£º ------------------------------- string SubFile=@"D:\Excel2.xls"; string...
0
by: mjwoods_2002 | last post by:
Hi, i am using C# to automate excel. i am trying to create a sheet of thumbnail images which i create in one worksheet and copy to another sheet. in vb.NET the code looks like this: ' copy the...
5
by: Anand | last post by:
Greetings, How can I find the number of active columns and rows used in an excel work sheet? What I mean is how can i find the last column and row or cell position, where the data is stored in...
2
by: Devlei | last post by:
How do I copy the contents of selected rows in a DataGrid (that is bound to a Dataset via a DataView) to the Clipboard for pasting into other applications - such as Excel? Doing the same from a...
4
by: gordon | last post by:
Hi I hav e a smallish app that has a datagridview. A user can select some columns in the datagrid, and i have a button that i would like to use to copy the rows that are selected to the...
0
by: nudrat | last post by:
Hi All, I have an excel sheet. I am able to read each cell values of excel sheet. Now i have a datagridview control. so how do i populate these cell values into datagridview control without using...
9
by: sitko | last post by:
Hi, I have an Order tracking spreadsheet that I need help with. I have a 2 worksheets "Open", and "Closed". I have entries on the "Open" sheet which may or may not be grouped together. I've...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.