diff --git a/src/System.Windows.Forms/src/PublicAPI.Shipped.txt b/src/System.Windows.Forms/src/PublicAPI.Shipped.txt index 9d1cfdfb048..a4fef9e14db 100644 --- a/src/System.Windows.Forms/src/PublicAPI.Shipped.txt +++ b/src/System.Windows.Forms/src/PublicAPI.Shipped.txt @@ -38,8 +38,8 @@ override System.Windows.Forms.DataGridView.OnMouseWheel(System.Windows.Forms.Mou override System.Windows.Forms.DataGridView.OnPaint(System.Windows.Forms.PaintEventArgs! e) -> void override System.Windows.Forms.DataGridView.OnResize(System.EventArgs! e) -> void override System.Windows.Forms.DataGridView.OnRightToLeftChanged(System.EventArgs! e) -> void -~override System.Windows.Forms.DataGridView.OnValidating(System.ComponentModel.CancelEventArgs e) -> void -~override System.Windows.Forms.DataGridView.OnVisibleChanged(System.EventArgs e) -> void +override System.Windows.Forms.DataGridView.OnValidating(System.ComponentModel.CancelEventArgs! e) -> void +override System.Windows.Forms.DataGridView.OnVisibleChanged(System.EventArgs! e) -> void override System.Windows.Forms.DataGridView.Text.get -> string! override System.Windows.Forms.DataGridView.Text.set -> void override System.Windows.Forms.DataGridViewButtonColumn.CellTemplate.get -> System.Windows.Forms.DataGridViewCell? @@ -767,30 +767,30 @@ virtual System.Windows.Forms.DataGridView.OnRowHeaderMouseClick(System.Windows.F virtual System.Windows.Forms.DataGridView.OnRowHeaderMouseDoubleClick(System.Windows.Forms.DataGridViewCellMouseEventArgs! e) -> void virtual System.Windows.Forms.DataGridView.OnRowHeadersBorderStyleChanged(System.EventArgs! e) -> void virtual System.Windows.Forms.DataGridView.OnRowHeadersDefaultCellStyleChanged(System.EventArgs! e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowHeadersWidthChanged(System.EventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowHeadersWidthSizeModeChanged(System.Windows.Forms.DataGridViewAutoSizeModeEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowHeightChanged(System.Windows.Forms.DataGridViewRowEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowHeightInfoNeeded(System.Windows.Forms.DataGridViewRowHeightInfoNeededEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowHeightInfoPushed(System.Windows.Forms.DataGridViewRowHeightInfoPushedEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowLeave(System.Windows.Forms.DataGridViewCellEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowMinimumHeightChanged(System.Windows.Forms.DataGridViewRowEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowPostPaint(System.Windows.Forms.DataGridViewRowPostPaintEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowPrePaint(System.Windows.Forms.DataGridViewRowPrePaintEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowsAdded(System.Windows.Forms.DataGridViewRowsAddedEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowsDefaultCellStyleChanged(System.EventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowsRemoved(System.Windows.Forms.DataGridViewRowsRemovedEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowStateChanged(int rowIndex, System.Windows.Forms.DataGridViewRowStateChangedEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowUnshared(System.Windows.Forms.DataGridViewRowEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowValidated(System.Windows.Forms.DataGridViewCellEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnRowValidating(System.Windows.Forms.DataGridViewCellCancelEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnScroll(System.Windows.Forms.ScrollEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnSelectionChanged(System.EventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnSortCompare(System.Windows.Forms.DataGridViewSortCompareEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnSorted(System.EventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnUserAddedRow(System.Windows.Forms.DataGridViewRowEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnUserDeletedRow(System.Windows.Forms.DataGridViewRowEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.OnUserDeletingRow(System.Windows.Forms.DataGridViewRowCancelEventArgs e) -> void -~virtual System.Windows.Forms.DataGridView.PaintBackground(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle gridBounds) -> void +virtual System.Windows.Forms.DataGridView.OnRowHeadersWidthChanged(System.EventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowHeadersWidthSizeModeChanged(System.Windows.Forms.DataGridViewAutoSizeModeEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowHeightChanged(System.Windows.Forms.DataGridViewRowEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowHeightInfoNeeded(System.Windows.Forms.DataGridViewRowHeightInfoNeededEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowHeightInfoPushed(System.Windows.Forms.DataGridViewRowHeightInfoPushedEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowLeave(System.Windows.Forms.DataGridViewCellEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowMinimumHeightChanged(System.Windows.Forms.DataGridViewRowEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowPostPaint(System.Windows.Forms.DataGridViewRowPostPaintEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowPrePaint(System.Windows.Forms.DataGridViewRowPrePaintEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowsAdded(System.Windows.Forms.DataGridViewRowsAddedEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowsDefaultCellStyleChanged(System.EventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowsRemoved(System.Windows.Forms.DataGridViewRowsRemovedEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowStateChanged(int rowIndex, System.Windows.Forms.DataGridViewRowStateChangedEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowUnshared(System.Windows.Forms.DataGridViewRowEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowValidated(System.Windows.Forms.DataGridViewCellEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnRowValidating(System.Windows.Forms.DataGridViewCellCancelEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnScroll(System.Windows.Forms.ScrollEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnSelectionChanged(System.EventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnSortCompare(System.Windows.Forms.DataGridViewSortCompareEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnSorted(System.EventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnUserAddedRow(System.Windows.Forms.DataGridViewRowEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnUserDeletedRow(System.Windows.Forms.DataGridViewRowEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.OnUserDeletingRow(System.Windows.Forms.DataGridViewRowCancelEventArgs! e) -> void +virtual System.Windows.Forms.DataGridView.PaintBackground(System.Drawing.Graphics! graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle gridBounds) -> void ~virtual System.Windows.Forms.DataGridView.ProcessDataGridViewKey(System.Windows.Forms.KeyEventArgs e) -> bool ~virtual System.Windows.Forms.DataGridView.Sort(System.Collections.IComparer comparer) -> void ~virtual System.Windows.Forms.DataGridView.Sort(System.Windows.Forms.DataGridViewColumn dataGridViewColumn, System.ComponentModel.ListSortDirection direction) -> void @@ -6238,10 +6238,10 @@ System.Windows.Forms.DataGridViewSelectionMode.FullColumnSelect = 2 -> System.Wi System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect = 1 -> System.Windows.Forms.DataGridViewSelectionMode System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect = 3 -> System.Windows.Forms.DataGridViewSelectionMode System.Windows.Forms.DataGridViewSortCompareEventArgs -System.Windows.Forms.DataGridViewSortCompareEventArgs.CellValue1.get -> object! -System.Windows.Forms.DataGridViewSortCompareEventArgs.CellValue2.get -> object! +System.Windows.Forms.DataGridViewSortCompareEventArgs.CellValue1.get -> object? +System.Windows.Forms.DataGridViewSortCompareEventArgs.CellValue2.get -> object? System.Windows.Forms.DataGridViewSortCompareEventArgs.Column.get -> System.Windows.Forms.DataGridViewColumn! -System.Windows.Forms.DataGridViewSortCompareEventArgs.DataGridViewSortCompareEventArgs(System.Windows.Forms.DataGridViewColumn! dataGridViewColumn, object! cellValue1, object! cellValue2, int rowIndex1, int rowIndex2) -> void +System.Windows.Forms.DataGridViewSortCompareEventArgs.DataGridViewSortCompareEventArgs(System.Windows.Forms.DataGridViewColumn! dataGridViewColumn, object? cellValue1, object? cellValue2, int rowIndex1, int rowIndex2) -> void System.Windows.Forms.DataGridViewSortCompareEventArgs.RowIndex1.get -> int System.Windows.Forms.DataGridViewSortCompareEventArgs.RowIndex2.get -> int System.Windows.Forms.DataGridViewSortCompareEventArgs.SortResult.get -> int diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridView.Methods.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridView.Methods.cs index f82ab995171..e221be394bc 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridView.Methods.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridView.Methods.cs @@ -18590,7 +18590,7 @@ protected virtual void OnRowHeadersDefaultCellStyleChanged(EventArgs e) GetEvent(s_rowHeadersDefaultCellStyleChangedEvent)?.Invoke(this, e); } -#nullable disable + private void OnRowHeadersGlobalAutoSize(bool expandingRows) { if (_noAutoSizeCount > 0) @@ -18605,24 +18605,24 @@ private void OnRowHeadersGlobalAutoSize(bool expandingRows) if (autoSizeRowHeaders) { - AutoResizeRowHeadersWidth(_rowHeadersWidthSizeMode, true /*fixedColumnHeadersHeight*/, fixedRowsHeight); + AutoResizeRowHeadersWidth(_rowHeadersWidthSizeMode, fixedColumnHeadersHeight: true, fixedRowsHeight); } if (!fixedRowsHeight) { if (expandingRows) { - AdjustExpandingRows(-1, true /*fixedWidth*/); + AdjustExpandingRows(columnIndex: -1, fixedWidth: true); } else { - AdjustShrinkingRows(_autoSizeRowsMode, true /*fixedWidth*/, true /*internalAutosizing*/); + AdjustShrinkingRows(_autoSizeRowsMode, fixedWidth: true, internalAutosizing: true); } if (autoSizeRowHeaders) { // Second round of row headers autosizing - AutoResizeRowHeadersWidth(_rowHeadersWidthSizeMode, true /*fixedColumnHeadersHeight*/, true /*fixedRowsHeight*/); + AutoResizeRowHeadersWidth(_rowHeadersWidthSizeMode, fixedColumnHeadersHeight: true, fixedRowsHeight: true); } } } @@ -18638,7 +18638,7 @@ protected virtual void OnRowHeadersWidthChanged(EventArgs e) UpdateMouseEnteredCell(hti: null, e: null); - OnRowHeadersGlobalAutoSize(false /*expandingRows*/); + OnRowHeadersGlobalAutoSize(expandingRows: false); } GetEvent(s_rowHeadersWidthChangedEvent)?.Invoke(this, e); @@ -18698,7 +18698,7 @@ private bool OnRowHeightInfoPushed(int rowIndex, int height, int minimumHeight) OnRowHeightInfoPushed(dgvrhipe); if (dgvrhipe.Handled) { - UpdateRowHeightInfoPrivate(rowIndex, false, true /*invalidInAdjustFillingColumns*/); + UpdateRowHeightInfoPrivate(rowIndex, updateToEnd: false, invalidInAdjustFillingColumns: true); return true; } } @@ -18709,7 +18709,7 @@ private bool OnRowHeightInfoPushed(int rowIndex, int height, int minimumHeight) protected virtual void OnRowHeightInfoPushed(DataGridViewRowHeightInfoPushedEventArgs e) => GetEvent(s_rowHeightInfoPushedEvent)?.Invoke(this, e); - private void OnRowLeave(ref DataGridViewCell dataGridViewCell, int columnIndex, int rowIndex) + private void OnRowLeave(ref DataGridViewCell? dataGridViewCell, int columnIndex, int rowIndex) { Debug.Assert(columnIndex >= 0 && rowIndex >= 0); if (rowIndex < Rows.Count && columnIndex < Columns.Count) @@ -18882,9 +18882,9 @@ private void OnRowSelectMouseMove(HitTestInfo hti) bool success = SetCurrentCellAddressCore(_ptCurrentCell.X, hti._row, - false /*setAnchorCellAddress*/, - false /*validateCurrentCell*/, - false /*throughMouseClick*/); + setAnchorCellAddress: false, + validateCurrentCell: false, + throughMouseClick: false); Debug.Assert(success); } } @@ -18982,7 +18982,11 @@ protected virtual void OnRowStateChanged(int rowIndex, DataGridViewRowStateChang FirstVisibleScrollingRowTempted(rowIndex); } - PerformLayoutPrivate(false /*useRowShortcut*/, false /*computeVisibleRows*/, true /*invalidInAdjustFillingColumns*/, true /*repositionEditingControl*/); + PerformLayoutPrivate( + useRowShortcut: false, + computeVisibleRows: false, + invalidInAdjustFillingColumns: true, + repositionEditingControl: true); Invalidate(); } @@ -18996,7 +19000,12 @@ protected virtual void OnRowStateChanged(int rowIndex, DataGridViewRowStateChang Rows.SetRowState(rowIndex, DataGridViewElementStates.Displayed, false); } - PerformLayoutPrivate(false /*useRowShortcut*/, false /*computeVisibleRows*/, true /*invalidInAdjustFillingColumns*/, true /*repositionEditingControl*/); + PerformLayoutPrivate( + useRowShortcut: false, + computeVisibleRows: false, + invalidInAdjustFillingColumns: true, + repositionEditingControl: true); + Invalidate(); bool rowDisplayed = (Rows.GetRowState(rowIndex) & DataGridViewElementStates.Displayed) != 0; @@ -19014,7 +19023,7 @@ protected virtual void OnRowStateChanged(int rowIndex, DataGridViewRowStateChang dataGridViewRow.CachedThickness = height; if (!((autoSizeRowsModeInternal & DataGridViewAutoSizeRowsModeInternal.DisplayedRows) != 0 && !rowDisplayed)) { - AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), false /*fixedWidth*/, true /*internalAutosizing*/); + AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), fixedWidth: false, internalAutosizing: true); autoSizeRow = true; } } @@ -19046,13 +19055,13 @@ protected virtual void OnRowStateChanged(int rowIndex, DataGridViewRowStateChang } else { - AutoResizeAllVisibleColumnsInternal(autoSizeColumnCriteriaFilter, true /*fixedHeight*/); + AutoResizeAllVisibleColumnsInternal(autoSizeColumnCriteriaFilter, fixedHeight: true); } if (autoSizeRow) { // Second round of row autosizing - AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), true /*fixedWidth*/, true /*internalAutosizing*/); + AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), fixedWidth: true, internalAutosizing: true); } break; @@ -19100,7 +19109,7 @@ protected virtual void OnRowUnshared(DataGridViewRowEventArgs e) GetEvent(s_rowUnsharedEvent)?.Invoke(this, e); } - private bool OnRowValidating(ref DataGridViewCell dataGridViewCell, int columnIndex, int rowIndex) + private bool OnRowValidating(ref DataGridViewCell? dataGridViewCell, int columnIndex, int rowIndex) { DataGridViewCellCancelEventArgs dgvcce = new(columnIndex, rowIndex); OnRowValidating(dgvcce); @@ -19142,7 +19151,7 @@ protected virtual void OnRowValidating(DataGridViewCellCancelEventArgs e) } } - private void OnRowValidated(ref DataGridViewCell dataGridViewCell, int columnIndex, int rowIndex) + private void OnRowValidated(ref DataGridViewCell? dataGridViewCell, int columnIndex, int rowIndex) { IsCurrentRowDirtyInternal = false; _dataGridViewState1[State1_NewRowCreatedByEditing] = false; @@ -19293,9 +19302,20 @@ protected virtual void OnSelectionChanged(EventArgs e) GetEvent(s_selectionChangedEvent)?.Invoke(this, e); } - internal bool OnSortCompare(DataGridViewColumn dataGridViewSortedColumn, object value1, object value2, int rowIndex1, int rowIndex2, out int sortResult) - { - DataGridViewSortCompareEventArgs dgvsce = new DataGridViewSortCompareEventArgs(dataGridViewSortedColumn, value1, value2, rowIndex1, rowIndex2); + internal bool OnSortCompare( + DataGridViewColumn dataGridViewSortedColumn, + object? value1, + object? value2, + int rowIndex1, + int rowIndex2, + out int sortResult) + { + DataGridViewSortCompareEventArgs dgvsce = new DataGridViewSortCompareEventArgs( + dataGridViewSortedColumn, + value1, + value2, + rowIndex1, + rowIndex2); OnSortCompare(dgvsce); sortResult = dgvsce.SortResult; return dgvsce.Handled; @@ -19315,9 +19335,9 @@ internal void OnSortGlyphDirectionChanged(DataGridViewColumnHeaderCell dataGridV if (dataGridViewColumnHeaderCell.SortGlyphDirection == SortOrder.None) { SortedColumn = null; - DataGridViewColumn dataGridViewColumn = dataGridViewColumnHeaderCell.OwningColumn; + DataGridViewColumn? dataGridViewColumn = dataGridViewColumnHeaderCell.OwningColumn; - if (dataGridViewColumn.IsDataBound) + if (dataGridViewColumn is not null && dataGridViewColumn.IsDataBound) { // If the column whose SortGlyphChanges is the sorted column and it is also the dataBound column // then see if there is another dataBound column which has the same property name as the sorted column. @@ -19326,7 +19346,8 @@ internal void OnSortGlyphDirectionChanged(DataGridViewColumnHeaderCell dataGridV { if (dataGridViewColumn != Columns[i] && Columns[i].SortMode != DataGridViewColumnSortMode.NotSortable - && string.Compare(dataGridViewColumn.DataPropertyName, + && string.Compare( + dataGridViewColumn.DataPropertyName, Columns[i].DataPropertyName, ignoreCase: true, CultureInfo.InvariantCulture) == 0) @@ -19353,10 +19374,12 @@ private void OnTopLeftHeaderMouseDown() if (_ptCurrentCell.X != -1) { // Potentially have to give focus back to the current edited cell. - bool success = SetCurrentCellAddressCore(_ptCurrentCell.X, _ptCurrentCell.Y, - false /*setAnchorCellAddress*/, - false /*validateCurrentCell*/, - false /*throughMouseClick*/); + bool success = SetCurrentCellAddressCore( + _ptCurrentCell.X, + _ptCurrentCell.Y, + setAnchorCellAddress: false, + validateCurrentCell: false, + throughMouseClick: false); Debug.Assert(success); } } @@ -19414,16 +19437,17 @@ protected override void OnValidating(CancelEventArgs e) { if (!_dataGridViewState1[State1_LeavingWithTabKey]) { - if (!EndEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.LeaveControl, - DataGridViewValidateCellInternal.Always, - false /*fireCellLeave*/, - false /*fireCellEnter*/, - false /*fireRowLeave*/, - false /*fireRowEnter*/, - false /*fireLeave*/, - false /*keepFocus*/, - false /*resetCurrentCell*/, - false /*resetAnchorCell unused here*/)) + if (!EndEdit( + DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.LeaveControl, + DataGridViewValidateCellInternal.Always, + fireCellLeave: false, + fireCellEnter: false, + fireRowLeave: false, + fireRowEnter: false, + fireLeave: false, + keepFocus: false, + resetCurrentCell: false, + resetAnchorCell: false)) { e.Cancel = true; return; @@ -19432,7 +19456,7 @@ protected override void OnValidating(CancelEventArgs e) if (_ptCurrentCell.X >= 0) { - DataGridViewCell dataGridViewCellTmp = null; + DataGridViewCell? dataGridViewCellTmp = null; if (OnRowValidating(ref dataGridViewCellTmp, _ptCurrentCell.X, _ptCurrentCell.Y)) { // Row validation was cancelled @@ -19454,7 +19478,9 @@ protected override void OnValidating(CancelEventArgs e) int rowIndex = Rows.GetPreviousRow(_ptCurrentCell.Y, DataGridViewElementStates.Visible); if (rowIndex > -1) { - bool success = SetAndSelectCurrentCellAddress(_ptCurrentCell.X, rowIndex, + bool success = SetAndSelectCurrentCellAddress( + _ptCurrentCell.X, + rowIndex, setAnchorCellAddress: true, validateCurrentCell: false, throughMouseClick: false, @@ -19465,10 +19491,12 @@ protected override void OnValidating(CancelEventArgs e) } else { - bool success = SetCurrentCellAddressCore(-1, -1, - true /*setAnchorCellAddress*/, - false /*validateCurrentCell*/, - false /*throughMouseClick*/); + bool success = SetCurrentCellAddressCore( + columnIndex: -1, + rowIndex: -1, + setAnchorCellAddress: true, + validateCurrentCell: false, + throughMouseClick: false); Debug.Assert(success); } } @@ -19559,10 +19587,10 @@ private void OnVisibleChangedPrivate() else { // Make sure all displayed bands lose the Displayed state - UpdateRowsDisplayedState(false /*displayed*/); + UpdateRowsDisplayedState(displayed: false); } - UpdateColumnsDisplayedState(Visible /*displayed*/); + UpdateColumnsDisplayedState(displayed: Visible); } protected virtual void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds) @@ -19705,14 +19733,15 @@ private void PaintColumnHeaders(Graphics g, Rectangle clipBounds, bool singleBor bandBounds = cellBounds = _layout.ColumnHeaders; bandBounds.Height = cellBounds.Height = _columnHeadersHeight; int cx = 0; - bool isFirstDisplayedColumn = true, isLastVisibleColumn = false; + bool isFirstDisplayedColumn = true; + bool isLastVisibleColumn = false; DataGridViewCell cell; DataGridViewCellStyle inheritedCellStyle = new DataGridViewCellStyle(); DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new(), dgvabsEffective; - DataGridViewColumn dataGridViewColumnNext = null; + DataGridViewColumn? dataGridViewColumnNext = null; // first paint the visible frozen columns - DataGridViewColumn dataGridViewColumn = Columns.GetFirstColumn(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); + DataGridViewColumn? dataGridViewColumn = Columns.GetFirstColumn(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); while (dataGridViewColumn is not null) { cell = dataGridViewColumn.HeaderCell; @@ -19734,7 +19763,8 @@ private void PaintColumnHeaders(Graphics g, Rectangle clipBounds, bool singleBor BuildInheritedColumnHeaderCellStyle(inheritedCellStyle, cell); - dataGridViewColumnNext = Columns.GetNextColumn(dataGridViewColumn, + dataGridViewColumnNext = Columns.GetNextColumn( + dataGridViewColumn, DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen, DataGridViewElementStates.None); if (dataGridViewColumnNext is null) @@ -19742,18 +19772,22 @@ private void PaintColumnHeaders(Graphics g, Rectangle clipBounds, bool singleBor isLastVisibleColumn = (DisplayedBandsInfo.FirstDisplayedScrollingCol < 0); } - dgvabsEffective = AdjustColumnHeaderBorderStyle(AdvancedColumnHeadersBorderStyle, dataGridViewAdvancedBorderStylePlaceholder, - isFirstDisplayedColumn, isLastVisibleColumn); + dgvabsEffective = AdjustColumnHeaderBorderStyle( + AdvancedColumnHeadersBorderStyle, + dataGridViewAdvancedBorderStylePlaceholder, + isFirstDisplayedColumn, + isLastVisibleColumn); // Microsoft: should paintSelectionBackground be dev-settable? - cell.PaintWork(g, - clipBounds, - cellBounds, - -1, - dataGridViewColumn.State, - inheritedCellStyle, - dgvabsEffective, - DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.SelectionBackground); + cell.PaintWork( + g, + clipBounds, + cellBounds, + -1, + dataGridViewColumn.State, + inheritedCellStyle, + dgvabsEffective, + DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.SelectionBackground); cx += cellBounds.Width; if (cx >= bandBounds.Width) @@ -19776,7 +19810,7 @@ private void PaintColumnHeaders(Graphics g, Rectangle clipBounds, bool singleBor if (DisplayedBandsInfo.FirstDisplayedScrollingCol >= 0 && cx < scrollingBounds.Width) { - Region clipRegion = null; + Region? clipRegion = null; if (FirstDisplayedScrollingColumnHiddenWidth > 0) { clipRegion = g.Clip; @@ -19819,8 +19853,11 @@ private void PaintColumnHeaders(Graphics g, Rectangle clipBounds, bool singleBor DataGridViewElementStates.None); isLastVisibleColumn = (dataGridViewColumnNext is null); - dgvabsEffective = AdjustColumnHeaderBorderStyle(AdvancedColumnHeadersBorderStyle, dataGridViewAdvancedBorderStylePlaceholder, - isFirstDisplayedColumn, isLastVisibleColumn); + dgvabsEffective = AdjustColumnHeaderBorderStyle( + AdvancedColumnHeadersBorderStyle, + dataGridViewAdvancedBorderStylePlaceholder, + isFirstDisplayedColumn, + isLastVisibleColumn); cell.PaintWork(g, clipBounds, @@ -19851,7 +19888,8 @@ private void PaintColumnHeaders(Graphics g, Rectangle clipBounds, bool singleBor } } - private void PaintGrid(Graphics g, + private void PaintGrid( + Graphics g, Rectangle gridBounds, Rectangle clipRect, bool singleVerticalBorderAdded, @@ -19948,7 +19986,7 @@ private void PaintRows(Graphics g, // this call may unshare the row. int rowHeight = Rows.SharedRow(indexTmp).GetHeight(indexTmp); Rows.SharedRow(indexTmp).CachedThickness = rowHeight; - AutoResizeRowInternal(indexTmp, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), false /*fixedWidth*/, true /*internalAutosizing*/); + AutoResizeRowInternal(indexTmp, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), fixedWidth: false, internalAutosizing: true); } rowBounds.Height = Rows.SharedRow(indexTmp).GetHeight(indexTmp); @@ -20004,7 +20042,7 @@ private void PaintRows(Graphics g, // this call may unshare the row. int rowHeight = Rows.SharedRow(indexTmp).GetHeight(indexTmp); Rows.SharedRow(indexTmp).CachedThickness = rowHeight; - AutoResizeRowInternal(indexTmp, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), false /*fixedWidth*/, true /*internalAutosizing*/); + AutoResizeRowInternal(indexTmp, MapAutoSizeRowsModeToRowMode(_autoSizeRowsMode), fixedWidth: false, internalAutosizing: true); } rowBounds.Height = Rows.SharedRow(indexTmp).GetHeight(indexTmp); @@ -20052,21 +20090,23 @@ private void PaintTopLeftHeaderCell(Graphics g) cellBounds.Width = RowHeadersWidth; cellBounds.Height = _columnHeadersHeight; // Microsoft: Should paintSelectionBackground be dev-settable? - cell.PaintWork(g, - _layout.TopLeftHeader, - cellBounds, - -1, - cell.State, - inheritedCellStyle, - AdjustedTopLeftHeaderBorderStyle, - DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.SelectionBackground); + cell.PaintWork( + g, + _layout.TopLeftHeader, + cellBounds, + -1, + cell.State, + inheritedCellStyle, + AdjustedTopLeftHeaderBorderStyle, + DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.SelectionBackground); } } - private void PerformLayoutPrivate(bool useRowShortcut, - bool computeVisibleRows, - bool invalidInAdjustFillingColumns, - bool repositionEditingControl) + private void PerformLayoutPrivate( + bool useRowShortcut, + bool computeVisibleRows, + bool invalidInAdjustFillingColumns, + bool repositionEditingControl) { _inPerformLayoutCount++; try @@ -20094,18 +20134,18 @@ private void PerformLayoutPrivate(bool useRowShortcut, // Some columns were auto-filled, the rows and column headers may need to be autosized. if ((((DataGridViewAutoSizeRowsModeInternal)_autoSizeRowsMode) & DataGridViewAutoSizeRowsModeInternal.AllColumns) != 0) { - AdjustShrinkingRows(_autoSizeRowsMode, true /*fixedWidth*/, true /*internalAutosizing*/); + AdjustShrinkingRows(_autoSizeRowsMode, fixedWidth: true, internalAutosizing: true); } if (ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.AutoSize) { - AutoResizeColumnHeadersHeight(true /*fixedRowHeadersWidth*/, true /*fixedColumnWidth*/); + AutoResizeColumnHeadersHeight(fixedRowHeadersWidth: true, fixedColumnsWidth: true); } } if (repositionEditingControl && EditingControl is not null) { - PositionEditingControl(true /*setLocation*/, false /*setSize*/, false /*setFocus*/); + PositionEditingControl(setLocation: true, setSize: false, setFocus: false); } } else @@ -20134,7 +20174,7 @@ private void PerformLayoutPrivate(bool useRowShortcut, Debug.Assert(_inPerformLayoutCount >= 0); } } - +#nullable disable private void PopulateNewRowWithDefaultValues() { if (NewRowIndex != -1) @@ -20261,7 +20301,7 @@ private void PositionEditingControl(bool setLocation, bool setSize, bool setFocu _editingPanel.Visible = true; if (setFocus) { - CorrectFocus(false /*onlyIfGridHasFocus*/); + CorrectFocus(onlyIfGridHasFocus: false); } } finally diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewRowCollection.RowComparer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewRowCollection.RowComparer.cs index 330ab9cf1c0..e6fbe42d812 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewRowCollection.RowComparer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewRowCollection.RowComparer.cs @@ -74,9 +74,20 @@ internal int CompareObjects(object? value1, object? value2, int rowIndex1, int r int result = 0; if (_customComparer is null) { - if (!_dataGridView.OnSortCompare(_dataGridViewSortedColumn, value1, value2, rowIndex1, rowIndex2, out result)) + if (_dataGridViewSortedColumn is null) { - if (!(value1 is IComparable) && !(value2 is IComparable)) + throw new InvalidOperationException(); + } + + if (!_dataGridView.OnSortCompare( + _dataGridViewSortedColumn, + value1, + value2, + rowIndex1, + rowIndex2, + out result)) + { + if (value1 is not IComparable && value2 is not IComparable) { if (value1 is null) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewSortCompareEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewSortCompareEventArgs.cs index 532d0aa9c34..e11eac39904 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewSortCompareEventArgs.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewSortCompareEventArgs.cs @@ -7,9 +7,10 @@ namespace System.Windows.Forms; public class DataGridViewSortCompareEventArgs : HandledEventArgs { - public DataGridViewSortCompareEventArgs(DataGridViewColumn dataGridViewColumn, - object cellValue1, - object cellValue2, + public DataGridViewSortCompareEventArgs( + DataGridViewColumn dataGridViewColumn, + object? cellValue1, + object? cellValue2, int rowIndex1, int rowIndex2) { @@ -22,9 +23,9 @@ public DataGridViewSortCompareEventArgs(DataGridViewColumn dataGridViewColumn, RowIndex2 = rowIndex2; } - public object CellValue1 { get; } + public object? CellValue1 { get; } - public object CellValue2 { get; } + public object? CellValue2 { get; } public DataGridViewColumn Column { get; }