C# - 将复制的行添加到datagrid视图 [英] C# - add copied row to datagrid view

查看:91
本文介绍了C# - 将复制的行添加到datagrid视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将此剪贴板的内容添加到要放置在原始数据表中的数据行? dataadapter和datatable声明不是全局的。



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.

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);
    }
}





此代码可以很好地获取所选行的信息。我该如何将其添加到datagrid的底部?目的是能够编辑复制的行以对其进行一些更改。我应该将它添加到新数据表并将其与原始数据表绑定到datagrid吗?



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?

推荐答案

这可以通过多种有趣的方式进行。

最简单的方法是处理网格上的keydown事件(捕获Ctrl + V)。



以下是一些可能有帮助的文章你 -

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 [ ^ ]





从网格复制到其他应用程序 - < a href =http://www.codeproject.com/Articles/36850/DataGridView-Copy-and-Paste> DataGridView复制和粘贴 [ ^ ]。
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[^].


这篇关于C# - 将复制的行添加到datagrid视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆