Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27017,7 +27017,8 @@ protected virtual bool SetCurrentCellAddressCore(int columnIndex,
int oldCurrentCellY = _ptCurrentCell.Y;
if (oldCurrentCellX >= 0
&& !_dataGridViewState1[State1_TemporarilyResetCurrentCell]
&& !_dataGridViewOper[OperationInDispose])
&& !_dataGridViewOper[OperationInDispose]
&& !_dataGridViewOper[OperationInReleasingDataSource])
{
DataGridViewCell currentCell = CurrentCellInternal;
if (!EndEdit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public partial class DataGridView : Control, ISupportInitialize
private const int OperationInEndEdit = 0x00400000;
private const int OperationResizingOperationAboutToStart = 0x00800000;
private const int OperationTrackKeyboardColResize = 0x01000000;
private const int OperationInReleasingDataSource = 0x02000000;
private const int OperationMouseOperationMask = OperationTrackColResize | OperationTrackRowResize |
OperationTrackColRelocation | OperationTrackColHeadersResize | OperationTrackRowHeadersResize;
private const int OperationKeyboardOperationMask = OperationTrackKeyboardColResize;
Expand Down Expand Up @@ -1921,7 +1922,17 @@ public object? DataSource
newDataSource.Disposed += OnDataSourceDisposed;
}

CurrentCell = null;
_dataGridViewOper[OperationInReleasingDataSource] = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually set this value inside the OnDataSourceDisposed instead of on any invocation of DataSource setter property? The new flag skips code that commits the value being editted, we want to skip the commit only if the control is diaposed and editing had not been completed.

Copy link
Member Author

@LeafShi1 LeafShi1 Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this makes more sense. CurrentCell = null; should also be placed in OnDataSourceDisposed, what do you think?

I submitted a new PR #13362

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CurrentCell = null; should stay because it manages event handlers and that logic is needed when DataSource is changed for reasons other that disposal.


try
{
CurrentCell = null;
}
finally
{
_dataGridViewOper[OperationInReleasingDataSource] = false;
}

if (DataConnection is null)
{
DataConnection = new DataGridViewDataConnection(this);
Expand Down