Click here to Skip to main content
13,357,583 members (67,211 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have 2 datagridview (dgvFrom and dgvTo) and 2 buttons with right and left arrows. dgvfrom is populated from dataset. Now when I select rows in dgvFrom and click right arrow button, selected rows should move to dgvTo grid and those selected rows should get deleted from dgvFrom grid.and vice versa for left arrow button.Can any1 help me with this.
Posted 31-Dec-12 20:24pm
What did you try so far? What was the problem?
Rachna0309 1-Jan-13 1:57am
For Each selRow As DataGridViewRow In dgvFrom.SelectedRows

I have tried with this code but it gives me error:
No row can be added without column.
Probably this is a problem of dfvTo; you did not add proper columns to it.
Rachna0309 1-Jan-13 2:06am
how to add columns to dgvto grid.
Look, if you already have dgvFrom, you already know how to add columns...
Rachna0309 1-Jan-13 2:15am
I have added columns in dgvfrom from dataset that was filled using query.Do i need to add columns in dgvto from datagridview design?
As you need to add the same rows, you should have the same columns, apparently.
Rachna0309 1-Jan-13 3:17am
Hello....can any1 provide me the solution?
You already have all key points. What else do you need. Just put it all together.
Rachna0309 1-Jan-13 2:25am
If I add columns in dgvTo from design I get the error below:
Row provided already belongs to a DataGridView control.
You need to create a row from scratch using just the data from another row.
Rachna0309 1-Jan-13 3:36am
Can you please put down the code for this?
In VB.NET. Honestly, don't want to add it to the installation of VS. Never install it and will hardly ever do it, sorry...
Look, one little effort and you will get it right. After all, you are the one most interested in that. Additionally, you will get a little practice solving some problems...
Rachna0309 1-Jan-13 3:38am
What if my dgvTo is also databound?
Probably won't work. Unbound it. Binding with a data source and manipulations with rows (or whatever) are contradictory, can't you see it? Or do it all with binding only: create a special data source which gives you desired result and refresh the control.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

this code might help you.

Dim DsTo As New DataSet '' '' Dataset for to DatagridView

'' '' Code on button Click
      for DgvToFor Each r As DataGridViewRow In DGVFrom.SelectedRows
           Dim Drto As DataRow = DsTo.Tables(0).NewRow
           For c As Integer = 0 To DGVFrom.ColumnCount - 1
               Drto(c) = r.Cells(c).Value

Rachna0309 1-Jan-13 4:29am
Thanks this code helped me..
Rahul K Singh 1-Jan-13 4:41am
Mark Solution if it helped you. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to remove them in one grid view and create in another one. Rows are not controls; in contrast to controls, you cannot "re-parent" them.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100