Solved

DataGridViewRowCollection

Posted on 2013-01-20
2
422 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

7 Experts available now in Live!

Get 1:1 Help Now