我需要能够从一个应用程序中复制一个或多个名称(使用正常的复制命令),然后能够双击 DataGridView 中的文本单元格以将数据粘贴到网格单元格中。关于如何做到这一点的任何想法?我正在尝试最小化此功能的键盘使用。
问问题
12694 次
3 回答
8
这实际上比您预期的要容易。
在 DataGridView 中创建一个 CellDoubleClick 事件,并在其中放置如下代码:
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Clipboard.GetText();
}
于 2009-10-06T20:05:42.580 回答
1
您应该将事件处理程序附加到单元格单击事件,并将单元格中的文本替换为Clipboard.GetText()
.
于 2009-10-06T20:01:38.067 回答
1
我写这个来复制一个通用的:
DataGridViewSelectedRowCollection dtSeleccionados = dataGrid.SelectedRows;
DataGridViewCellCollection dtCells;
String row;
String strCopiado = "";
for (int i = dtSeleccionados.Count - 1; i >= 0; i--)
{
dtCells = dtSeleccionados[i].Cells;
row = "";
for (int j = 0; j < dtCells.Count; j++)
{
row = row + dtCells[j].Value.ToString() + (((j + 1) == dtCells.Count) ? "" : "\t");
}
strCopiado = strCopiado + row + "\n";
}
try
{
Clipboard.SetText(strCopiado);
}
catch (ArgumentNullException ex)
{
Console.Write(ex.ToString());
}
于 2010-03-22T23:29:53.753 回答