private void SheetDataGridViewMouseDownEvent(object sender, MouseEventArgs e) { int columns = SheetDataGridView.Columns.GetColumnCount(DataGridViewElementStates.Visible); int rows = (ExplorerForm.GetResultDataGridView().RowCount == 0) ? 0 : SheetDataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible); int row = (columns == 0) ? 0 : SheetDataGridView.RowCount; DeleteColumnMenuItem.Enabled = columns != 0; DeleteRowsMenuItem.Enabled = rows != 0; DeleteRowMenuItem.Enabled = row != 0; RestoreColumnsMenuItem.Enabled = columns < GetSheetColumnInitialTotal(); if (e.Button == MouseButtons.Right) { DataGridView.HitTestInfo hitTest = SheetDataGridView.HitTest(e.X, e.Y); switch (hitTest.Type) { case DataGridViewHitTestType.ColumnHeader: SheetDataGridView.ClearSelection(); SheetDataGridView.CurrentCell = SheetDataGridView[hitTest.ColumnIndex, 0]; break; case DataGridViewHitTestType.RowHeader: if (columns != 0) { SheetDataGridView.ClearSelection(); SheetDataGridView.CurrentCell = SheetDataGridView[SheetDataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible).DisplayIndex, hitTest.RowIndex]; } break; case DataGridViewHitTestType.Cell: if (hitTest.RowIndex >= 0) { SheetDataGridView.ClearSelection(); SheetDataGridView.CurrentCell = SheetDataGridView[hitTest.ColumnIndex, hitTest.RowIndex]; } break; default: DeleteColumnMenuItem.Enabled = false; break; } } }
private void DeleteColumnMenuItemClick(object sender, System.EventArgs e) { if (SheetDataGridView.CurrentCell != null) { DataGridViewColumn FirstVisibleColumn = SheetDataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible); int iFirstColumnIndex = FirstVisibleColumn.DisplayIndex; int iOwningColumnIndex = SheetDataGridView.CurrentCell.OwningColumn.Index; SheetDataGridView.ClearSelection(); SheetDataGridView.Columns[iOwningColumnIndex].Visible = false; if (iFirstColumnIndex == iOwningColumnIndex) { ClassLibraryFramework.DataGridViewMethods.SortOnFirstVisibleColumn(SheetDataGridView); } WorkTables.SetSheetDataGridViewFocus(); ComparisonReset(); } }