复制并粘贴到 DataGridView 单元格 (C#) [英] Copy and paste into a DataGridView cell (C#)

查看:24
本文介绍了复制并粘贴到 DataGridView 单元格 (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够从一个应用程序复制一个或多个名称(使用正常的复制命令),然后能够双击 DataGridView 中的文本单元格以将数据粘贴到网格单元格中.关于如何做到这一点的任何想法?我正在尝试尽量减少此功能的键盘使用.

I need to be able to copy a name or names from one application (using the normal copy commands) and then be able to double click the text cell in a DataGridView to paste the data into the grid cell. Any ideas on how to accomplish this? I am attempting to minimize keyboard use for this functionality.

推荐答案

这实际上比你想象的要容易.

This is actually easier than you might expect.

在 DataGridView 中创建一个 CellDoubleClick 事件,并在其中放入如下代码:

Create a CellDoubleClick event in your DataGridView and in it put code like this:

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
   dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Clipboard.GetText();
}

这篇关于复制并粘贴到 DataGridView 单元格 (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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