Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can I add the content of this clipboard to a datarow to be placed in the original datatable? The dataadapter and datatable declarations are not global.

C#
if (this.dataGridView1.GetCellCount(DataGridViewElementStates.Selected) > 0)
{
    try
    {

        DataGridViewRow dgvr = new DataGridViewRow();
        Clipboard.SetDataObject(this.dataGridView1.GetClipboardContent());
        dataGridView1.Rows.Add(Clipboard.GetText());


    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


This code gets the information of the selected row fine. How should I go about adding this to the bottom of the datagrid? The intent is to be able to edit the copied row to make a few changes to it. Should I add this to a new datatable and bind this with the original datatable to the datagrid?
Posted

1 solution

This could be possible to do in a number of interesting ways.
The simplest would be to handle the the keydown event on the grid (capture Ctrl + V).

Here are some articles that might help you -
http://jrwren.wrenfam.com/blog/2007/09/08/datagridview-databound-copy-paste-drag-drop/[^]
http://happysoftware.blogspot.in/2011/07/c-code-snippet-paste-to-datagridview.html[^]


Copy from grid to other applications - DataGridView Copy and Paste[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900