Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Comments
Sergey Alexandrovich Kryukov 1-Jan-13 1:53am    
What did you try so far? What was the problem?
—SA
Rachna0309 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 1-Jan-13 2:05am    
Probably this is a problem of dfvTo; you did not add proper columns to it.
—SA
Rachna0309 1-Jan-13 2:06am    
how to add columns to dgvto grid.
Sergey Alexandrovich Kryukov 1-Jan-13 2:10am    
Look, if you already have dgvFrom, you already know how to add columns...
—SA

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
 
Share this answer
 
v2
Comments
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. :)
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900