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

datagrid copy rows

Hello Group,
I have 2 datagrids and the first one is bound to a
database. Each row consists of checkbox, textbox etc.. As the user makes
the selection, I want to add the corresponding row to the other datagrid.
Unable to figure out how to copy rows in DG. Any help would be appreciated!

Thanks,
Chris.
Jul 21 '05 #1
3 1440
Hi Chris,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add rows from one DataGrid
to the other. If there is any misunderstanding, please feel free to let me
know.

Generally, when we need to add rows from one DataGrid to the other, we have
to add rows in the source DataSet. Here is an example. when you click a row
on one DataGrid, that row will be added to the other DataGrid.

private void Form1_Load(object sender, System.EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Employees",
this.sqlConnection1);
this.ds1 = new DataSet();
this.ds2 = new DataSet();
sda.FillSchema(ds1, SchemaType.Source);
sda.FillSchema(ds2, SchemaType.Source);
sda.Fill(ds1);
this.dataGrid1.DataSource = ds1.Tables[0];
this.dataGrid2.DataSource = ds2.Tables[0];

cm = (CurrencyManager)this.BindingContext[this.ds1.Tables[0]];
cm.CurrentChanged +=new EventHandler(cm_CurrentChanged);
}

private void cm_CurrentChanged(object sender, EventArgs e)
{

this.ds2.Tables[0].Rows.Add(this.ds1.Tables[0].Rows[this.cm.Position].ItemAr
ray);
}

HTH. 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."

Jul 21 '05 #2
sam
I should have mentioned that I am talking in the context of web data
grid.
The idea seems to be clear and I am trying to incorporate the same but
any sample code(asp.net/vb.net) could be appreciated!

Thanks,
Chris.

v-****@online.microsoft.com (Kevin Yu [MSFT]) wrote in message news:<C4**************@cpmsftngxa10.phx.gbl>...
Hi Chris,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add rows from one DataGrid
to the other. If there is any misunderstanding, please feel free to let me
know.

Generally, when we need to add rows from one DataGrid to the other, we have
to add rows in the source DataSet. Here is an example. when you click a row
on one DataGrid, that row will be added to the other DataGrid.

private void Form1_Load(object sender, System.EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Employees",
this.sqlConnection1);
this.ds1 = new DataSet();
this.ds2 = new DataSet();
sda.FillSchema(ds1, SchemaType.Source);
sda.FillSchema(ds2, SchemaType.Source);
sda.Fill(ds1);
this.dataGrid1.DataSource = ds1.Tables[0];
this.dataGrid2.DataSource = ds2.Tables[0];

cm = (CurrencyManager)this.BindingContext[this.ds1.Tables[0]];
cm.CurrentChanged +=new EventHandler(cm_CurrentChanged);
}

private void cm_CurrentChanged(object sender, EventArgs e)
{

this.ds2.Tables[0].Rows.Add(this.ds1.Tables[0].Rows[this.cm.Position].ItemAr
ray);
}

HTH. 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."

Jul 21 '05 #3
Hi Chris,

In an ASP.NET senario, we can use the same idea to add row values, except
handling the CurrentChanged event and using CurrencyManager. We can use a
button to fire the event and search for checked rows to add.

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

Jul 21 '05 #4

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

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Steve | last post by:
I have a datagrid that is created at run time DataGrid dgG = new DataGrid(); BoundColumn bcB; dgG.CellPadding = 5; dgG.CellSpacing = 0; dgG.GridLines = GridLines.Both; dgG.CssClass =...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
1
by: mark | last post by:
I fear my initial post was misleading. I have a Windows application. I have a numerical array which is displayed in a datagrid by way of a datatable and a dataview. I want my user to be...
7
by: Dave | last post by:
Are there any add-on products or samples available that can do the following in an vb.net datagrid I want to compare 2 rows in a datagrid - one row from one database and another row for another...
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...
6
by: Rob | last post by:
I am trying to copy some data from one datagrid to another. The first datagrid containing data is called DocList. The blank Datagrid that I am trying to copy some data to is called DataGrid1. ...
6
by: Bill Nguyen | last post by:
I need to add a checkbox in front of all the rows in a datagrid so that users can select/unselect them. Any help is greatly appreciated! Bill
6
by: Bill nguyen | last post by:
I use DatagridTableStyle to display data from table WF_Carrier_FreightChart. USers than can add/delete/edit rows in the Datagrid. Since the Datagrid's datasource "dCarrierFreight" is just a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.