DGV throws IndexOutOfRangeException whenever its datasource is disposed (servicing)#4637
Merged
RussKie merged 1 commit intodotnet:release/5.0from Mar 10, 2021
Merged
DGV throws IndexOutOfRangeException whenever its datasource is disposed (servicing)#4637RussKie merged 1 commit intodotnet:release/5.0from
IndexOutOfRangeException whenever its datasource is disposed (servicing)#4637RussKie merged 1 commit intodotnet:release/5.0from
Conversation
…taSource (dotnet#4551) to DataGridView and BindingNavigator. Fixes dotnet#4216 A DataGridView threw IndexOutOfRangeException when its DataSource is already disposed and the DataGridView try to redraw itself, because its Rows and Columns are not updated but DataSource is already released. The DataGridView try to draw rows that are not exist in DataConnection, it send some index (eg. 5) to items collection and catch the exception because this index is out of empty items collection range. Initially, the issue repoduced when a user closes a form with DataGridView and BindingNavigator, because the form disposes BindingSource when closing and then disposes BindingNavigator, that try to redraw DataGridView. It is due to BindingNavigator send UiaReturnRawElementProvider message to Windows and it redraws DGV sometimes (looks like a bug). We tried to cancel DGV redwawing if a form is closing. Then we found the second case: we cought this IndexOutOfRangeException if to just dispose DataSource without form closing. So the issue is DataGridView Rows and Columns are not updated when DataSource disposing. This fix uses Dispose events to set null for DataGridView.DataSource and BindingNavigator.BindingSource thereby call refresh of internal collections of their items. (cherry picked from commit 3f9c8e7)
Contributor
Author
|
Approved for servicing over email |
Codecov Report
@@ Coverage Diff @@
## release/5.0 #4637 +/- ##
=====================================================
+ Coverage 68.27670% 68.33471% +0.05800%
=====================================================
Files 1421 1421
Lines 510713 510837 +124
Branches 41580 41584 +4
=====================================================
+ Hits 348698 349079 +381
+ Misses 155658 155396 -262
- Partials 6357 6362 +5
Flags with carried forward coverage won't be shown. Click here to find out more. |
dreddy-work
approved these changes
Mar 7, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4216
Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
After
DataGridViewandBindingNavigatorsubscribed on theBindingSource.Disposedevent and release theirDataSourceandBindingSourceto update internal collectionsTest methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow