From 59c9ba4d0b7d4ed386caa7eef99d7babe66c9f1c Mon Sep 17 00:00:00 2001 From: Sai Sivani Koppolu Date: Wed, 15 Jul 2026 15:36:55 +0530 Subject: [PATCH] added fix and test for issue 1929 --- .../DataGridView/DataGridViewCheckBoxCell.cs | 17 ++----------- .../Windows/Forms/DataGridViewCellTests.cs | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs index c16bbeace51..85e76e744b1 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs @@ -516,14 +516,6 @@ OwningColumn is null || return Rectangle.Empty; } - Point ptCurrentCell = DataGridView.CurrentCellAddress; - if (ptCurrentCell.X == ColumnIndex && - ptCurrentCell.Y == rowIndex && DataGridView.IsCurrentCellInEditMode) - { - // PaintPrivate does not paint the error icon if this is the current cell. - // So don't set the ErrorIconBounds either. - return Rectangle.Empty; - } ComputeBorderStyleCellStateAndCellBounds( rowIndex, @@ -1073,16 +1065,11 @@ private Rectangle PaintPrivate( valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; bool cellSelected = (elementState & DataGridViewElementStates.Selected) != 0; - bool drawAsMixedCheckBox = false, drawErrorText = true; + bool drawAsMixedCheckBox = false; CheckState checkState; ButtonState bs; Debug.Assert(DataGridView is not null); Point ptCurrentCell = DataGridView.CurrentCellAddress; - if (ptCurrentCell.X == ColumnIndex && - ptCurrentCell.Y == rowIndex && DataGridView.IsCurrentCellInEditMode) - { - drawErrorText = false; - } if (formattedValue is not null and CheckState state) { @@ -1554,7 +1541,7 @@ private Rectangle PaintPrivate( resultBounds = Rectangle.Empty; } - if (paint && PaintErrorIcon(paintParts) && drawErrorText && DataGridView.ShowCellErrors) + if (paint && PaintErrorIcon(paintParts) && DataGridView.ShowCellErrors) { PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } diff --git a/src/test/unit/System.Windows.Forms/System/Windows/Forms/DataGridViewCellTests.cs b/src/test/unit/System.Windows.Forms/System/Windows/Forms/DataGridViewCellTests.cs index 74a0d767a62..33186b72933 100644 --- a/src/test/unit/System.Windows.Forms/System/Windows/Forms/DataGridViewCellTests.cs +++ b/src/test/unit/System.Windows.Forms/System/Windows/Forms/DataGridViewCellTests.cs @@ -77,6 +77,30 @@ public void DataGridViewCell_ContentBounds_GetWithColumn_ReturnsExpected() Assert.Equal(Rectangle.Empty, cell.ContentBounds); } + [WinFormsFact] + public void DataGridViewCheckBoxCell_ErrorIconBounds_RemainsVisible_InEditMode() + { + using DataGridView dgv = new() + { + Size = new Size(100, 40), + ShowCellErrors = true + }; + dgv.CreateControl(); + + using DataGridViewCheckBoxColumn column = new(); + dgv.Columns.Add(column); + dgv.Rows.Add(); + + var cell = (DataGridViewCheckBoxCell)dgv.Rows[0].Cells[0]; + cell.Value = false; + cell.ErrorText = "err"; + + dgv.CurrentCell = cell; + dgv.BeginEdit(true); + + Assert.NotEqual(Rectangle.Empty, cell.ErrorIconBounds); + } + [WinFormsFact] public void DataGridViewCell_ContentBounds_GetWithDataGridView_ReturnsExpected() {