?
Solved

DataGridViewRowCollection

Posted on 2013-01-20
2
Medium Priority
?
448 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
[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 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

741 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