Skip to content

Commit b33f1ba

Browse files
committed
Add _isReleasingDataSource to prevent unnecessary operations on CurrentCell when changing or releasing DataSource (#13320)
Fixes #13304 Root cause Regression introduced in PR #4637 When closing the dialog in edit mode, DataSource is set to null, and then CurrentCell = null is set. Then unnecessary method EndEdit of the SetCurrentCellAddressCore is called. Proposed changes Add _isReleasingDataSource in DataGridView and set it to null in property DataSource before setting CurrentCell = null to prevent the EndEdit method of the SetCurrentCellAddressCore from being called Customer Impact When the DataGridView is in editing mode, its dialog box can be closed normally Regression? Yes Risk Minimal
1 parent 32b207b commit b33f1ba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/DataGridView.Methods.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27462,7 +27462,8 @@ protected virtual bool SetCurrentCellAddressCore(int columnIndex,
2746227462
int oldCurrentCellY = _ptCurrentCell.Y;
2746327463
if (oldCurrentCellX >= 0 &&
2746427464
!_dataGridViewState1[State1_TemporarilyResetCurrentCell] &&
27465-
!_dataGridViewOper[OperationInDispose])
27465+
!_dataGridViewOper[OperationInDispose] &&
27466+
!_dataGridViewOper[OperationInReleasingDataSource])
2746627467
{
2746727468
DataGridViewCell currentCell = CurrentCellInternal;
2746827469
if (!EndEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.CurrentCellChange,

src/System.Windows.Forms/src/System/Windows/Forms/DataGridView.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public partial class DataGridView : Control, ISupportInitialize
224224
private const int OperationInEndEdit = 0x00400000;
225225
private const int OperationResizingOperationAboutToStart = 0x00800000;
226226
private const int OperationTrackKeyboardColResize = 0x01000000;
227+
private const int OperationInReleasingDataSource = 0x02000000;
227228
private const int OperationMouseOperationMask = OperationTrackColResize | OperationTrackRowResize |
228229
OperationTrackColRelocation | OperationTrackColHeadersResize | OperationTrackRowHeadersResize;
229230
private const int OperationKeyboardOperationMask = OperationTrackKeyboardColResize;
@@ -2044,7 +2045,17 @@ public object DataSource
20442045
newDataSource.Disposed += OnDataSourceDisposed;
20452046
}
20462047

2047-
CurrentCell = null;
2048+
_dataGridViewOper[OperationInReleasingDataSource] = true;
2049+
2050+
try
2051+
{
2052+
CurrentCell = null;
2053+
}
2054+
finally
2055+
{
2056+
_dataGridViewOper[OperationInReleasingDataSource] = false;
2057+
}
2058+
20482059
if (DataConnection is null)
20492060
{
20502061
DataConnection = new DataGridViewDataConnection(this);

0 commit comments

Comments
 (0)