Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[release/8.0] InvalidOperationException when closing a dialog with focused DataGridView control #13350

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

Merged

Conversation

LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Apr 23, 2025

Backport of #13320 to release/8.0
Fixes #13304

Proposed changes

  • When the DataGridView is in edit mode and the parent form is being closed, the DataGridView's EndEdit triggers the CurrentCell setting logic, because the DGV's handle has been destroyed at this time, we are re-creating it and then re-enter logic that sets up the current cell causing an exception to be thrown. Checking isHandleCreated before calling EndEdit can avoid executing related logic when the control has been destroyed, thereby preventing exceptions from occurring.

Customer Impact

  • When the DataGridView is in editing mode, its dialog box can be closed normally

Regression?

Testing

  • Manual testing with the user-provided project

Risk

  • Low
Microsoft Reviewers: Open in CodeFlow

…ntCell when changing or releasing DataSource (dotnet#13320)

Fixes dotnet#13304

Root cause
Regression introduced in PR dotnet#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
@LeafShi1 LeafShi1 requested a review from a team as a code owner April 23, 2025 02:34
@LeafShi1 LeafShi1 changed the title Add _isReleasingDataSource to prevent unnecessary operations on CurrentCell when changing or releasing DataSource (#13320) [release/8.0] Add _isReleasingDataSource to prevent unnecessary operations on CurrentCell when changing or releasing DataSource Apr 23, 2025
@LeafShi1 LeafShi1 requested a review from Tanya-Solyanik April 23, 2025 02:35
…sposed" (dotnet#13362)

* Removing tag OperationInReleasingDataSource

* Add judgment IsHandleCreated to before defining currentCell in function SetCurrentCellAddressCore
@LeafShi1 LeafShi1 force-pushed the backport/pr-13320-to-release/8.0 branch from fdf2875 to 209b149 Compare April 25, 2025 01:17
@Tanya-Solyanik Tanya-Solyanik changed the title [release/8.0] Add _isReleasingDataSource to prevent unnecessary operations on CurrentCell when changing or releasing DataSource [release/8.0] InvalidOperationException when closing a dialog with focused DataGridView control Apr 25, 2025
@Tanya-Solyanik Tanya-Solyanik added this to the 9.0.6 milestone Apr 25, 2025
@Tanya-Solyanik Tanya-Solyanik added 🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria servicing-approved .NET Shiproom approved the PR for merge and removed servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria labels Apr 25, 2025
@LeafShi1 LeafShi1 merged commit a29c04a into dotnet:release/8.0 May 8, 2025
8 checks passed
@LeafShi1 LeafShi1 removed the 🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
servicing-approved .NET Shiproom approved the PR for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants