Click here to Skip to main content
11,709,536 members (44,378 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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 19:24pm
Sergey Alexandrovich Kryukov at 1-Jan-13 1:53am
What did you try so far? What was the problem?
Rachna0309 at 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.
Sergey Alexandrovich Kryukov at 1-Jan-13 2:05am
Probably this is a problem of dfvTo; you did not add proper columns to it.
Rachna0309 at 1-Jan-13 2:06am
how to add columns to dgvto grid.
Sergey Alexandrovich Kryukov at 1-Jan-13 2:10am
Look, if you already have dgvFrom, you already know how to add columns...
Rachna0309 at 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?
Sergey Alexandrovich Kryukov at 1-Jan-13 2:21am
As you need to add the same rows, you should have the same columns, apparently.
Rachna0309 at 1-Jan-13 3:17am
Hello....can any1 provide me the solution?
Sergey Alexandrovich Kryukov at 1-Jan-13 3:31am
You already have all key points. What else do you need. Just put it all together.
Rachna0309 at 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.
Sergey Alexandrovich Kryukov at 1-Jan-13 3:30am
You need to create a row from scratch using just the data from another row.
Rachna0309 at 1-Jan-13 3:36am
Can you please put down the code for this?
Sergey Alexandrovich Kryukov at 1-Jan-13 3:44am
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 at 1-Jan-13 3:38am
What if my dgvTo is also databound?
Sergey Alexandrovich Kryukov at 1-Jan-13 3:41am
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 at 1-Jan-13 4:29am
Thanks this code helped me..
Rahul K Singh at 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
0 Sergey Alexandrovich Kryukov 590
1 OriginalGriff 250
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2015
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