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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now