Click here to Skip to main content
Rate this: bad
good
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
Comments
Sergey Alexandrovich Kryukov at 1-Jan-13 1:53am
   
What did you try so far? What was the problem?
—SA
Rachna0309 at 1-Jan-13 1:57am
   
For Each selRow As DataGridViewRow In dgvFrom.SelectedRows
dgvTo.Rows.Add(selRow)
dgvFrom.Rows.Remove(selRow)
Next
 
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.
—SA
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...
—SA
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.
—SA
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.
—SA
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.
—SA
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...
—SA
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.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
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
           Next
           DsTo.Tables(0).Rows.Add(Drto)
           DGVFrom.Rows.Remove(r)
       Next
 

RKS
  Permalink  
v2
Comments
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
good
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.
 
—SA
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
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