private void Paste() { int insertNewRowAt; if (_cutActivated) { string firstNameOfSelectedRows = FirstNameOfSelectedRows(); insertNewRowAt = GetIndexOfRowFromName(firstNameOfSelectedRows); int totalRows = dataGridView1.Rows.Count; int spaceLeft = totalRows - insertNewRowAt; if (spaceLeft < _copiedItems.Count) { insertNewRowAt = totalRows - _copiedItems.Count; } if (insertNewRowAt < 0) { insertNewRowAt = 0; } } else { string lastNameOfSelectedRows = LastNameOfSelectedRows(); insertNewRowAt = GetIndexOfRowFromName(lastNameOfSelectedRows) + 1; } int insertNewRowAtOriginal = insertNewRowAt; if (_cutActivated) { DoDelete(_copiedItems); } List <string> nameList = new List <string>(); foreach (Stylesheet itemToBeCopied in _copiedItems) { string name = StylesheetHelper.GetNewItemName(itemToBeCopied.Name); Stylesheet newItem = new Stylesheet(name, itemToBeCopied.Description, itemToBeCopied.Xslt, itemToBeCopied.Enabled, itemToBeCopied.OutputFormat); CreateNewItem(newItem, insertNewRowAt); insertNewRowAt++; nameList.Add(name); } foreach (DataGridViewRow row in dataGridView1.Rows) { row.Selected = false; } dataGridView1.CurrentCell = dataGridView1["StylesheetName", insertNewRowAtOriginal]; SelectRows(nameList); FillStepColumn(); PopulateSearchList(); UpdateStylesheetsTextBox(); SetChangesMade(true); dataGridView1.Focus(); }