Solved

DataGridViewRowCollection

Posted on 2013-01-20
2
445 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 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

718 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