当DataGridView.SelectionMode是FullRowSelect剪贴板复制失败 [英] Clipboard copy fails when DataGridView.SelectionMode is FullRowSelect

查看:759
本文介绍了当DataGridView.SelectionMode是FullRowSelect剪贴板复制失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows窗体,如果我创建夫妇的行和列的简单DataGridView控件,然后设置SelectionMode属性设置为FullRowSelect,我得到剪贴板的复制功能奇怪的行为:



当选择了行和用户点击CTRL-C,全行被复制到剪贴板与细胞之间的\t字符,符合市场预期。



当单个细胞被双击和由用户编辑,并且该小区用户内选择文本的一部分,并击中CTRL-C,静止的整排被复制,并且所选择的文本不是部<!/对>

作为一种变通方法我试图做keydown事件拷贝到剪贴板,但是当编辑控件处于编辑模式下,不触发事件。


$ b ?$ b

任何建议


解决方案

为workarround:



编辑时禁止拷贝到剪贴板

 私人无效dataGridView1_CellBeginEdit(对象发件人,DataGridViewCellCancelEventArgs E)
{
this.dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
}

私人无效dataGridView1_CellEndEdit(对象发件人,DataGridViewCellEventArgs E)
{
this.dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
}


In windows forms, if I create a simple DataGridView control with couple of rows and columns, and then set the SelectionMode property to FullRowSelect, I get strange behaviour with the clipboard's copy function:

When a row is selected and user hits ctrl-c, the full row is copied to the clipboard with \t characters between cells, as expected.

When a single cell is double-clicked and edited by user, and inside that cell user selects a portion of a text and hits ctrl-c, STILL the whole row is copied, and not the portion of the selected text!

As a workaround i tried to do the clipboard copy on keydown event, but the event is not fired when editing control is in edit mode.

Any suggestions?

解决方案

as workarround:

disable the clipboard copy when editing

  private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
    {
        this.dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
    }

    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        this.dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
    }

这篇关于当DataGridView.SelectionMode是FullRowSelect剪贴板复制失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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