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.
A:
You should attach an eventhandler to the cell clicked event and replace the text in the cell by the data in Clipboard.GetText()
.
Jan Jongboom
2009-10-06 20:01:38
+3
A:
This is actually easier than you might expect.
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();
}
Jay Riggs
2009-10-06 20:05:42
That's what I needed. Thanks a million.
DaBomb
2009-10-06 20:14:14
Good! No problem.
Jay Riggs
2009-10-06 20:41:40
This is the easiest way to accomplish copy and paste. But is there anyway I can enable use to right click and then paste on to the datagridview.
Ani
2010-09-21 16:31:05
A:
Ive Made to copy a generic:
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());
}
luis_green
2010-03-22 23:29:53