Copy and paste into a DataGridView cell (C#)(复制并粘贴到 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#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:复制并粘贴到 DataGridView 单元格 (C#)
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
