Copy and paste multiple cells within DataGridView
Ok, I got a solution but it hasn't been tested by pasting cells accross multiple rows.This is the KeyDown event of the datagridview
if (e.Control && e.KeyCode == Keys.C)
{
DataObject d = AccountGrid.GetClipboardContent();
Clipboard.SetDataObject(d);
e.Handled = true;
}
else if (e.Control && e.KeyCode == Keys.V)
{
string s = Clipboard.GetText();
string[] lines = s.Split('\n');
int row = AccountGrid.CurrentCell.RowIndex;
int col = AccountGrid.CurrentCell.ColumnIndex;
string[] cells = lines[0].Split('\t');
int cellsSelected = cells.Length;
for (int i = 0; i < cellsSelected; i++)
{
AccountGrid[col, row].Value = cells[i];
col++;
}
}