views:

1333

answers:

3

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
+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
That's what I needed. Thanks a million.
DaBomb
Good! No problem.
Jay Riggs
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
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