private void KeysList_CellContentClick(object sender, DataGridViewCellEventArgs e) { var grid = sender as DataGridView; if (grid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { if (e.ColumnIndex == 1) { RSAEncryptor.OpenKeyEdit(true, RSAEncryptor.keys[e.RowIndex]); } else if (e.ColumnIndex == 2) { RSAEncryptor.RemoveKey(e.RowIndex); grid.Rows.RemoveAt(e.RowIndex); KeysList.ClearSelection(); UpdateItemsSize(); } } }