Solved

How do I copy and past one or more rows from a Data Grid View into the same Data Grid View

Posted on 2010-08-13
4
183 Views
Last Modified: 2013-06-12
Hi I have some code that works for one row the issue is that it includes the ID value from the row selected as this needs to be unique it does not work.

Private Sub CopyRows(ByVal DGVGrid As DataGridView, ByVal SourceRowID As Integer, ByVal DestinationRowID As Integer)


        For j As Integer = 0 To DGVGrid.Rows(SourceRowID).Cells.Count - 1

            DGVGrid.Rows(DestinationRowID).Cells(j).Value = DGVGrid.Rows(SourceRowID).Cells(j).Value
        Next

    End Sub


   
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim myRowIndex As Integer = Examination_Of_Lifting_EquipmentDataGridView.CurrentRow.Index
        For count As Integer = 0 To Examination_Of_Lifting_EquipmentDataGridView.Rows.Count - 1
            CopyRows(Examination_Of_Lifting_EquipmentDataGridView, myRowIndex, myRowIndex + 1)
        Next
    End Sub
0
Comment
Question by:rhill52
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 500 total points
ID: 33430260
this is just a suggestion.
Why not you go with javascript solution for the same.

here is scenariio:

you can put checkboxes / copy links for each row in grid.
and on any event call javascript function and add <td> with same table (rendered grid).

here is reference:

http://www.codeguru.com/forum/showthread.php?t=446823

http://social.msdn.microsoft.com/forums/en-US/netfxjscript/thread/9c62b867-8a86-4fb8-ab50-21118939b517/

Also you can use ajax...

http://www.codegod.de/webappcodegod/GridView-Javascript-Click-Row-and-Ajax-AID302.aspx

Hope this helps you.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33431110
I tried Your Code And it only copy 1 row after the last selected row.For Multiple Selection When the datagridview is databound (tried for me) i got exception for that reason ...
(Because it is databound ...)..
0
 

Author Comment

by:rhill52
ID: 33452343
Hi Jtoutou

Yes it only copies one row, but the issue I have is the first column is the ID coloumn that has an autonumber set so I need a way of excluding this coloumn if possible.

Thanks
0
 

Author Comment

by:rhill52
ID: 34213407
in the end I removed the ID coloumn from the datagrid view and the code works my question now is why is it so slow, the more data in the datagrid the slower the copy.

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET Repostiory Pattern 7 37
VB.Net Report Printing Issue 3 35
Sql server insert 13 31
Help with consolidating excel files using VB.net 2 24
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question