private void dataGridView_KeyDown(object sender, KeyEventArgs e) { var selectedRows = dataGridView.SelectedRows; var selectedCells = dataGridView.SelectedCells; if (!Content.FilterLogic.IsFiltered) //data is in read only mode.... { if (e.KeyCode == Keys.Delete && selectedCells.Count == Content.Rows && selectedCells.Count > 0) { Content.DeleteColumn(selectedCells[0].ColumnIndex); } else if (e.KeyCode == Keys.Delete && selectedRows.Count > 0) { List <int> rows = new List <int>(); for (int i = 0; i < selectedRows.Count; ++i) { int index = (sortedColumnIndices.Count != 0) ? (Convert.ToInt32(selectedRows[i].HeaderCell.Value) - 1) : selectedRows[i].Index; rows.Add(index); } Content.DeleteRows(rows); } else if (e.Control && e.KeyCode == Keys.F) { CreateFindAndReplaceDialog(); findAndReplaceDialog.ActivateSearch(); } else if (e.Control && e.KeyCode == Keys.R) { CreateFindAndReplaceDialog(); findAndReplaceDialog.ActivateReplace(); } } }
protected override void dataGridView_KeyDown(object sender, KeyEventArgs e) { base.dataGridView_KeyDown(sender, e); //data is in read only mode.... if (Content.PreprocessingData.IsFiltered) return; if (e.KeyCode == Keys.Delete) { //Delete column if (dataGridView.SelectedColumns.Count > 0) { var columnsToDelete = dataGridView.SelectedColumns.Cast<DataGridViewColumn>().OrderByDescending(col => col.Index).ToList(); foreach (var col in columnsToDelete) Content.DeleteColumn(col.Index); } //Delete row if (dataGridView.SelectedRows.Count > 0) { //necessary if columns are sorted to translate the selected row index var rowIndexes = dataGridView.SelectedRows.Cast<DataGridViewRow>().Select(row => GetRowIndex(row.Index)).ToList(); Content.DeleteRows(rowIndexes); } } else if (e.Control && e.KeyCode == Keys.F) { CreateFindAndReplaceDialog(); findAndReplaceDialog.ActivateSearch(); } else if (e.Control && e.KeyCode == Keys.R) { CreateFindAndReplaceDialog(); findAndReplaceDialog.ActivateReplace(); } }