datagrid copy rows

C

chris

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.
 
K

Kevin Yu [MSFT]

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

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.
 
K

Kevin Yu [MSFT]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top