473,598 Members | 3,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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("Exce l");

if (Clipboard.Cont ainsData(DataFo rmats.CommaSepa ratedValue))

{

clipboardData = Clipboard.GetDa taObject();

using (StreamReader reader = new StreamReader((S tream)(clipboar dData.GetData(D ataFormats.Comm aSeparatedValue ))))

{

while (reader.Peek() > 0)

{

excelRow = reader.ReadLine ();

colValues = excelRow.Split( ',');

if (! (excelTable.Col umns.Count > 0))

{

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

{

excelTable.Colu mns.Add();

}

}

row = excelTable.NewR ow();

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

{

row[i] = colValues.GetVa lue(i);

}

excelTable.Rows .Add(row);

}

}

}
uxGrid.DataSour ce = excelTable;
Apr 5 '07 #1
0 1992

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

Similar topics

9
4640
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 with same. Instead, they (heavy spreadsheet users...) want to "Copy and Paste" financial return percentages for various funds into the DB. The source of these copies may be ascii text...but it's also likely to be an Excel spreadsheet on occasion.
1
3381
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 MainFile=@"D:\Excel.xls"; Excel.Application ExcelMainFileApp,ExcelSubFileApp;
0
1214
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 chart as a picture ..ActiveChart.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen, Size:=Excel.XlPictureAppearance.xlScreen, Format:=Excel.XlCopyPictureFormat.xlBitmap) ..ActiveWorkbook.Sheets("Graphs_100%Vol").Select()...
5
10704
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 an excel sheet? A code snippet would be of great help. Thanks for your cooperation and help.
2
3116
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 TextBox is easy via the TextBox.SelectedText property, but I can't find the DataGrid property to do the same for the selected rows.
4
5844
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 clipboard or to a text file. Any ideas how to accomplish this? I have all the controls working in this form apart from this feature.
0
1794
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 Oledb provider. my excel sheet is in row column format exactly like a data table of any database. plz find a solution for that. its really urgent. Thanks & Regards Nudrat
9
16762
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 called the rows :Parents and Children. There are basically 3 types of rows. Parents with Children, Parents without Children, and Children. I have a reference cell for each row, where I identify what type of row it is, "-1" = Child, "0" = Parent with...
7
12060
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
7987
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...
1
8050
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
8264
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
5438
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
3897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
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
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.