2

我有一个 datagridview myDgv 数据将从数据库填充到其中。

当我将复制的数据粘贴到 excel 中时,我正在执行 Ctrl+A (全选)和复制( Ctrl + C ),只有前 50 行数据被复制。
其余行为空白。

这是我的 keydown 事件中的代码

If e.Control AndAlso e.KeyCode = Keys.C Then
    Dim d As DataObject = myDgv.GetClipboardContent()
    Clipboard.SetDataObject(d)
    e.Handled = True
End If

当我向下滚动网格直到结束(最后一行)并执行 Ctrl+C 然后将其粘贴到 excel 中时,所有行都被粘贴了。

我该如何着手解决这个问题?

4

1 回答 1

0

使用DataGridView.SelectAll方法来选择使用 ctrl + A 上的所有行。

并使用以下事件来按下按键:

void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control && e.KeyCode == Keys.C)
    {
        //call to DataGridView.SelectAll Method
    }
}
于 2013-02-14T10:08:12.207 回答