Skip to content

Commit 848bacb

Browse files
authored
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 628aeb8 commit 848bacb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27017,7 +27017,8 @@ protected virtual bool SetCurrentCellAddressCore(int columnIndex,
2701727017
int oldCurrentCellY = _ptCurrentCell.Y;
2701827018
if (oldCurrentCellX >= 0
2701927019
&& !_dataGridViewState1[State1_TemporarilyResetCurrentCell]
27020-
&& !_dataGridViewOper[OperationInDispose])
27020+
&& !_dataGridViewOper[OperationInDispose]
27021+
&& !_dataGridViewOper[OperationInReleasingDataSource])
2702127022
{
2702227023
DataGridViewCell currentCell = CurrentCellInternal;
2702327024
if (!EndEdit(

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public partial class DataGridView : Control, ISupportInitialize
222222
private const int OperationInEndEdit = 0x00400000;
223223
private const int OperationResizingOperationAboutToStart = 0x00800000;
224224
private const int OperationTrackKeyboardColResize = 0x01000000;
225+
private const int OperationInReleasingDataSource = 0x02000000;
225226
private const int OperationMouseOperationMask = OperationTrackColResize | OperationTrackRowResize |
226227
OperationTrackColRelocation | OperationTrackColHeadersResize | OperationTrackRowHeadersResize;
227228
private const int OperationKeyboardOperationMask = OperationTrackKeyboardColResize;
@@ -1921,7 +1922,17 @@ public object? DataSource
19211922
newDataSource.Disposed += OnDataSourceDisposed;
19221923
}
19231924

1924-
CurrentCell = null;
1925+
_dataGridViewOper[OperationInReleasingDataSource] = true;
1926+
1927+
try
1928+
{
1929+
CurrentCell = null;
1930+
}
1931+
finally
1932+
{
1933+
_dataGridViewOper[OperationInReleasingDataSource] = false;
1934+
}
1935+
19251936
if (DataConnection is null)
19261937
{
19271938
DataConnection = new DataGridViewDataConnection(this);

0 commit comments

Comments
 (0)