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
204 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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