Skip to content

Commit a21947d

Browse files
committed
Moving tag OperationInReleasingDataSource to function "OnDataSourceDisposed" (#13362)
* Removing tag OperationInReleasingDataSource * Add judgment IsHandleCreated to before defining currentCell in function SetCurrentCellAddressCore
1 parent 4f21312 commit a21947d

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27484,10 +27484,10 @@ protected virtual bool SetCurrentCellAddressCore(int columnIndex,
2748427484
{
2748527485
int oldCurrentCellX = _ptCurrentCell.X;
2748627486
int oldCurrentCellY = _ptCurrentCell.Y;
27487-
if (oldCurrentCellX >= 0
27487+
if (IsHandleCreated
27488+
&& oldCurrentCellX >= 0
2748827489
&& !_dataGridViewState1[State1_TemporarilyResetCurrentCell]
27489-
&& !_dataGridViewOper[OperationInDispose]
27490-
&& !_dataGridViewOper[OperationInReleasingDataSource])
27490+
&& !_dataGridViewOper[OperationInDispose])
2749127491
{
2749227492
DataGridViewCell currentCell = CurrentCellInternal;
2749327493
if (!EndEdit(

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ 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;
226225
private const int OperationMouseOperationMask = OperationTrackColResize | OperationTrackRowResize |
227226
OperationTrackColRelocation | OperationTrackColHeadersResize | OperationTrackRowHeadersResize;
228227
private const int OperationKeyboardOperationMask = OperationTrackKeyboardColResize;
@@ -1922,16 +1921,7 @@ public object? DataSource
19221921
newDataSource.Disposed += OnDataSourceDisposed;
19231922
}
19241923

1925-
_dataGridViewOper[OperationInReleasingDataSource] = true;
1926-
1927-
try
1928-
{
1929-
CurrentCell = null;
1930-
}
1931-
finally
1932-
{
1933-
_dataGridViewOper[OperationInReleasingDataSource] = false;
1934-
}
1924+
CurrentCell = null;
19351925

19361926
if (DataConnection is null)
19371927
{

0 commit comments

Comments
 (0)