-
Notifications
You must be signed in to change notification settings - Fork 1k
Add _isReleasingDataSource to prevent unnecessary operations on CurrentCell when changing or releasing DataSource #13320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ntCell when changing or releasing DataSource
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #13320 +/- ##
===================================================
- Coverage 62.56333% 62.56145% -0.00188%
===================================================
Files 1560 1560
Lines 159675 159675
Branches 14904 14904
===================================================
- Hits 99898 99895 -3
- Misses 59008 59011 +3
Partials 769 769
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR prevents unnecessary operations on CurrentCell when changing or releasing DataSource by introducing a new flag.
- Added a private flag (_isReleasingDataSource) to signal when DataSource is being released.
- Wrapped the CurrentCell update in a try-finally block to maintain flag integrity.
- Updated the SetCurrentCellAddressCore method to check the new flag and prevent calling EndEdit unnecessarily.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
DataGridView.cs | Introduced _isReleasingDataSource and updated the DataSource setter to use a try-finally block when setting CurrentCell. |
DataGridView.Methods.cs | Modified the condition in SetCurrentCellAddressCore to skip EndEdit when _isReleasingDataSource is true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a small comment, please sent to testing when done. Is it possible to add a unit test to the UI tests assembly?
@@ -345,6 +345,7 @@ private const DataGridViewAutoSizeRowCriteriaInternal InvalidDataGridViewAutoSiz | |||
private int _inBulkPaintCount; | |||
private int _inBulkLayoutCount; | |||
private int _inPerformLayoutCount; | |||
private bool _isReleasingDataSource; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add another bit flag to this field _dataGridViewOper instead of a new bool?
Fixes #13304
Root cause
Regression introduced in PR #4637
When closing the dialog in edit mode,
DataSource
is set to null, and thenCurrentCell = null
is set. Then unnecessary methodEndEdit
of theSetCurrentCellAddressCore
is called.Proposed changes
_isReleasingDataSource
in DataGridView and set it to null in propertyDataSource
before settingCurrentCell = null
to prevent theEndEdit
method of the SetCurrentCellAddressCore from being calledCustomer Impact
Regression?
Risk
Screenshots
Before
When a dialog with a DataGridView that has focus is closed, an
System.InvalidOperationException: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
is thrownDataGridViewCrash.mp4
After
The DataGridView dialog with focus can be closed successfully
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow