forked from dotnet/winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing IndexOutOfRangeException throwing by DGV when disposing its Da…
…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)
- Loading branch information
1 parent
937b05a
commit 5c06649
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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