public void Paste(string[][] values) { DataGridViewCell startCell = null; int maxColumn = -1; // Find startCell and end column to paste foreach (DataGridViewCell cell in SelectedCells) { if (startCell == null || cell.ColumnIndex < startCell.ColumnIndex) { startCell = cell; } if (startCell == null || cell.ColumnIndex > maxColumn) { maxColumn = cell.ColumnIndex; } } if (startCell == null) { startCell = Rows[0].Cells[0]; } if (maxColumn == -1) { maxColumn = 0; } // Now paste the data int numColumns = maxColumn - startCell.ColumnIndex; if (numColumns == 0) { numColumns = 999999; } bool pasteWithErrors = false; Cursor = Cursors.WaitCursor; for (int i = 0; i < values.GetLength(0); i++) { Rows.Add(); for (int j = 0; j <= numColumns && j < values[i].Length; j++) { try { object val = CurrentCell.ParseFormattedValue(values[i][j], CurrentCell.Style, null, null); CurrentCell = Rows[RowCount - 2].Cells[startCell.ColumnIndex + j]; CurrentCell.Value = val; } catch { pasteWithErrors = true; } } this.ProcessDownKey(Keys.Down); } Cursor = Cursors.Default; if (pasteWithErrors) { MessageBox.Show(Culture.Get("strPasteWithErrors")); } CurrentCell = startCell; }