Click here to Skip to main content
13,045,790 members (47,159 online)
Rate this:
Please Sign up or sign in to vote.
See more: , +
Hi All,
How we can copy one or more than one rows from a data grid view to other data grid view on same form. Here, I've searching option which search from the first grid and if found some matching rows then copy them to 2nd grid. How I can achieve this ?
Posted 9-Jul-12 20:59pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

For Each rw As DataGridViewRow In dg.Rows
           Dim i As Integer = dg1.Rows.Add(TryCast(rw.Clone, DataGridView))
           For Each cl As DataGridViewCell In rw.Cells
               dg1.Rows(i).Cells(cl.ColumnIndex).Value = cl.Value
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You need to make a loop on source gridview and then check each row and select which one you want to copy then with the help of 'Rows.Add' method we can add rows to destination gridview
see below snippet
DataGridViewRow row = new DataGridViewRow();
       for (int i = 0; i < sourceGRD1.Rows.Count; i++)
           row = (DataGridViewRow)sourceGRD1.Rows[i].Clone();
           int intColIndex = 0;
           foreach (DataGridViewCell cell in sourceGRD1.Rows[i].Cells)
               row.Cells[intColIndex].Value = cell.Value;
       destnationGRD1.AllowUserToAddRows = false;

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 | Mobile
Web01 | 2.8.170713.1 | Last Updated 29 Dec 2015
Copyright © CodeProject, 1999-2017
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