Solved

DataGridViewRowCollection

Posted on 2013-01-20
2
427 Views
Last Modified: 2013-01-21
hi - I'm using C# and ,net 4.
I'm trying to implement a copy and paste from a datagridview to a datagridview by row. it would seem that i can use the DataGridViewRowCollection that is returned from property "SelectedRows". after acquiring the collection, i use the method "CopyTo" to copy to an array of DGV rows. the count is correct. the documentation says "Copies the elements of the collection to the specified array, starting at the specified index."
but i then try to extract the cell value from each item in the collection and its null.
note that i'm using the cell index since it doesn't find the column name and throws an error. there are 8 items in teh row.

the code is below:
foreach (DataGridViewRow dgvRow in copyRows.AsEnumerable())
                    {

                        DataRow drg = CurrentScriptTable.NewRow();

                        drg["script_Id"] = currentScript;
                        drg["lineNumber"] = scriptDisplay_DGV.CurrentRow.Index + k;
                        drg["label"] = dgvRow.Cells[2].Value.ToString();

                        CurrentScriptTable.Rows.InsertAt(drg, scriptDisplay_DGV.CurrentRow.Index + k++);
                    }
any suggestions?
0
Comment
Question by:jdcoburn
2 Comments
 

Author Comment

by:jdcoburn
ID: 38799635
hi -- an additional piece of information that occurs to me and may be the cause of my problem - the datagridview is data bound. I wonder if copying the selection outside of the original de-references the collection from the datatable it is bound to? therefore the values are not available when i go to paste them.
Jim
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 38801223
Why are you using InsertAt?  Wouldn't CurrentScriptTable be a collection of selected rows?  I would think that you just need to append the rows to CurrentScriptTable.

CurrentScriptTable.Rows.InsertAt(drg, scriptDisplay_DGV.CurrentRow.Index + k++);
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

17 Experts available now in Live!

Get 1:1 Help Now