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
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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