Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
208 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 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 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