-
Notifications
You must be signed in to change notification settings - Fork 984
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
Fixing IndexOutOfRangeException throwing by DGV when disposing its DataSource #4551
Fixing IndexOutOfRangeException throwing by DGV when disposing its DataSource #4551
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4551 +/- ##
===================================================
+ Coverage 97.96079% 97.96244% +0.00164%
===================================================
Files 542 543 +1
Lines 263533 264188 +655
Branches 4937 4968 +31
===================================================
+ Hits 258159 258805 +646
- Misses 4494 4500 +6
- Partials 880 883 +3
Flags with carried forward coverage won't be shown. Click here to find out more. |
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.
👍
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.
LGTM.
Testers approved the changes ✔️ |
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.
0ba2b87
to
7b2c0ca
Compare
…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)
Fixes #4216
Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
After
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow