Thursday, 29 January 2015

How to move selected rows of one DataGridView to another DataGridView .



I have 2 datagridview (dgvfrom and dgTo2) and 2 buttons with right and left arrows. dgvfrom is populated from dataset. Now when I select rows in dgvFrom and  doubleclick on RowHeader, selected rows should move to dgvTo grid and those selected rows should get deleted from dgvFrom grid.


I have add some record in dgvfrom DataGridView

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgvfrom.Rows.Add(5)
        '''''row1
        dgvfrom.Rows(0).Cells(0).Value = "Manish"
        dgvfrom.Rows(0).Cells(1).Value = "Agra"
        dgvfrom.Rows(0).Cells(2).Value = "9760737517"
        dgvfrom.Rows(0).Cells(3).Value = "manishfmca2009@gmail.com"
        dgvfrom.Rows(0).Cells(4).Value = "www.visualstudioexpert.com"


        '''''row2
        dgvfrom.Rows(1).Cells(0).Value = "Manish"
        dgvfrom.Rows(1).Cells(1).Value = "Agra"
        dgvfrom.Rows(1).Cells(2).Value = "9760737517"
        dgvfrom.Rows(1).Cells(3).Value = "manishfmca2009@gmail.com"
        dgvfrom.Rows(1).Cells(4).Value = "www.visualstudioexpert.com"


        '''''row3
        dgvfrom.Rows(2).Cells(0).Value = "Ajay"
        dgvfrom.Rows(2).Cells(1).Value = "Agra"
        dgvfrom.Rows(2).Cells(2).Value = "9719800859"
        dgvfrom.Rows(2).Cells(3).Value = "ajay@gmail.com"
        dgvfrom.Rows(2).Cells(4).Value = "www.visualstudioexpert.com"


        '''''row4
        dgvfrom.Rows(3).Cells(0).Value = "Nikhil"
        dgvfrom.Rows(3).Cells(1).Value = "Agra"
        dgvfrom.Rows(3).Cells(2).Value = "9412315106"
        dgvfrom.Rows(3).Cells(3).Value = "nikhil_yad@gmail.com"
        dgvfrom.Rows(3).Cells(4).Value = "www.visualstudioexpert.com"


        '''''row5
        dgvfrom.Rows(4).Cells(0).Value = "Jitendra"
        dgvfrom.Rows(4).Cells(1).Value = "Agra"
        dgvfrom.Rows(4).Cells(2).Value = "8272821832"
        dgvfrom.Rows(4).Cells(3).Value = "jitendra@gmail.com"
        dgvfrom.Rows(4).Cells(4).Value = "www.visualstudioexpert.com"
    End Sub

show in figure1.





















Private Sub dgvfrom_RowHeaderMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvfrom.RowHeaderMouseDoubleClick
   
  Dim d(10) As String

     
        d(0) = dgvfrom.Rows(0).Cells(0).Value.ToString
        d(1) = dgvfrom.Rows(0).Cells(0).Value.ToString
        d(2) = dgvfrom.Rows(0).Cells(0).Value.ToString
        d(3) = dgvfrom.Rows(0).Cells(0).Value.ToString
        d(4) = dgvfrom.Rows(0).Cells(0).Value.ToString
        dgvTo.Rows.Add(d)
        dgvfrom.Rows.Remove(dgvfrom.SelectedRows.Item(0))

   
    End Sub

show in figure 2.





















I hope you its will help you






No comments:

Post a Comment

Working with 3- Tier Architecture in C#

  Introduction In this article we will learn Use to 3- Tier architecture in C#.NET application. 3-Tier architecture is very famous and ...