Skip to content
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

DataGridView filter caused IndexOutOfRangeException #4216

Closed
coderb opened this issue Nov 11, 2020 · 14 comments · Fixed by #4551 or #4637
Closed

DataGridView filter caused IndexOutOfRangeException #4216

coderb opened this issue Nov 11, 2020 · 14 comments · Fixed by #4551 or #4637
Assignees
Labels
area-Controls-DataGridView 🪲 bug Product bug (most likely) 💥 regression-preview Regression from a preview release tenet-accessibility MAS violation, UIA issue; problems with accessibility standards

Comments

@coderb
Copy link

coderb commented Nov 11, 2020

  • .NET Core Version: .NET 5.0.100

  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:
I have a DataGridView with a DataView data source that I use the set a RowFilter. It mostly works, but I just got the following stack (with a Dialog popup). I've never seen this prior to .net 5.0.

Popup: DataGridView Default Error Dialog
The following exception occurred in the DataGridView:
System.IndexOutOfRangeException: Index 1 does not have a value.
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at System.Windows.Forms.DataGridView.DataGridViewConnection.GetError(Int32 rowIndex)
 	[Managed to Native Transition]	
 	System.Windows.Forms.Primitives.dll!Interop.User32.MessageBoxW(System.Runtime.InteropServices.HandleRef hWnd, string lpText, string lpCaption, Interop.User32.MB uType)	Unknown
 	System.Windows.Forms.dll!System.Windows.Forms.MessageBox.ShowCore(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, bool showHelp) Line 413	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnDataError(bool displayErrorDialogIfNoHandler, System.Windows.Forms.DataGridViewDataErrorEventArgs e) Line 14636	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnDataErrorInternal(System.Windows.Forms.DataGridViewDataErrorEventArgs e) Line 14650	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(int rowIndex) Line 1193	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.GetErrorText(int rowIndex) Line 1221	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle rowBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow) Line 1402	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintRows(System.Drawing.Graphics g, System.Drawing.Rectangle boundingRect, System.Drawing.Rectangle clipRect, bool singleHorizontalBorderAdded) Line 19610	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintGrid(System.Drawing.Graphics g, System.Drawing.Rectangle gridBounds, System.Drawing.Rectangle clipRect, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded) Line 19482	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnPaint(System.Windows.Forms.PaintEventArgs e) Line 16607	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e, short layer) Line 8621	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m) Line 12345	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 12741	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.WndProc(ref System.Windows.Forms.Message m) Line 29102	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 115	C#
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 372	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	System.Windows.Forms.Primitives.dll!Interop.UiaCore.UiaHostProviderFromHwnd(System.Runtime.InteropServices.HandleRef hwnd, out Interop.UiaCore.IRawElementProviderSimple ppProvider)	Unknown
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlAccessibleObject.HostRawElementProvider.get() Line 537	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	System.Windows.Forms.dll!System.Windows.Forms.AccessibleObject.RaiseAutomationEvent(Interop.UiaCore.UIA eventId) Line 1949	C#
>	System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.DataGridViewCellAccessibleObject.SetFocus() Line 594	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.AccessibilityNotifyCurrentCellChanged(System.Drawing.Point cellAddress) Line 54	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(int columnIndex, int rowIndex, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick) Line 26233	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(int columnIndex, int rowIndex, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick, bool clearSelection, bool forceCurrentCellSelection) Line 26596	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.MatchCurrencyManagerPosition(bool scrollIntoView, bool clearSelection) Line 1336	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_PositionChanged(object sender, System.EventArgs e) Line 803	C#
 	System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.OnPositionChanged(System.EventArgs e) Line 971	C#
 	System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.List_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) Line 742	C#
 	System.Data.Common.dll!System.Data.DataView.OnListChanged(System.ComponentModel.ListChangedEventArgs e) Line 1434	C#
 	System.Data.Common.dll!System.Data.DataView.UpdateIndex(bool force, bool fireEvent) Line 1634	C#
 	System.Data.Common.dll!System.Data.DataView.SetIndex2(string newSort, System.Data.DataViewRowState newRowStates, System.Data.IFilter newRowFilter, bool fireEvent) Line 1559	C#
 	System.Data.Common.dll!System.Data.DataView.SetIndex(string newSort, System.Data.DataViewRowState newRowStates, System.Data.IFilter newRowFilter) Line 1538	C#
 	System.Data.Common.dll!System.Data.DataView.RowFilter.set(string value) Line 337	C#
 	myapp.dll!myapp.MyDataView.SetRowFilter(string value) Line 64	C#
 	myapp.dll!myapp.MyDataGridViewContextMenu.miFilterFieldAdd_Click(object sender, System.EventArgs e) Line 293	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripMenuItem.OnClick(System.EventArgs e) Line 898	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleClick(System.EventArgs e) Line 2397	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleMouseUp(System.Windows.Forms.MouseEventArgs e) Line 2579	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) Line 3667	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripDropDown.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) Line 1357	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) Line 12106	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 12885	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Line 1457	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m) Line 4848	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripDropDown.WndProc(ref System.Windows.Forms.Message m) Line 2098	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 115	C#
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 372	C#
 	[Native to Managed Transition]	

@RussKie
Copy link
Member

RussKie commented Nov 11, 2020

Please provide a simple repro.

@RussKie RussKie added the 📭 waiting-author-feedback The team requires more information from the author label Nov 11, 2020
@RussKie
Copy link
Member

RussKie commented Nov 11, 2020

@coderb are you using accessibility tools, like Inspect or Narrator?

>	System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.DataGridViewCellAccessibleObject.SetFocus() Line 594	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.AccessibilityNotifyCurrentCellChanged(System.Drawing.Point cellAddress) Line 54	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(int columnIndex, int rowIndex, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick) Line 26233	C#

@vladimir-krestov @SergeySmirnov-Akvelon please check this call stack.

@RussKie RussKie added the waiting-review This item is waiting on review by one or more members of team label Nov 11, 2020
@coderb
Copy link
Author

coderb commented Nov 11, 2020

Please provide a simple repro.

I can't repro it currently but if I can I will post. Perhaps there is some kind of race with the Paint event.

@ghost ghost removed the 📭 waiting-author-feedback The team requires more information from the author label Nov 11, 2020
@coderb
Copy link
Author

coderb commented Nov 11, 2020

@coderb are you using accessibility tools, like Inspect or Narrator?

>	System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.DataGridViewCellAccessibleObject.SetFocus() Line 594	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.AccessibilityNotifyCurrentCellChanged(System.Drawing.Point cellAddress) Line 54	C#
 	System.Windows.Forms.dll!System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(int columnIndex, int rowIndex, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick) Line 26233	C#

@vladimir-krestov @SergeySmirnov-Akvelon please check this call stack.

no

@RussKie RussKie added 📭 waiting-author-feedback The team requires more information from the author and removed waiting-review This item is waiting on review by one or more members of team labels Nov 12, 2020
@SergeySmirnov-Akvelon
Copy link
Contributor

SergeySmirnov-Akvelon commented Nov 13, 2020

i found a similar error when user does the following steps:

  1. Create an application with a DataGridView.
  2. Add a BindingSource and a BindingNavigator to the DataGridView.
  3. Or just open the attached project (4216.zip)
  4. Run the application
  5. Start editing the last row (row to add a new row)
  6. Close the application while editing the row

Issue-4216-1

System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.this[int].get(int index) Line 307	C#
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(int rowIndex) Line 1182	C#
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.GetErrorText(int rowIndex) Line 1225	C#
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle rowBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow) Line 1402	C#
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintRows(System.Drawing.Graphics g, System.Drawing.Rectangle boundingRect, System.Drawing.Rectangle clipRect, bool singleHorizontalBorderAdded) Line 19545	C#
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.PaintGrid(System.Drawing.Graphics g, System.Drawing.Rectangle gridBounds, System.Drawing.Rectangle clipRect, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded) Line 19431	C#
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnPaint(System.Windows.Forms.PaintEventArgs e) Line 16559	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e, short layer) Line 8612	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m) Line 12334	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 12732	C#
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.WndProc(ref System.Windows.Forms.Message m) Line 29054	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 67	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 119	C#
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 372	C#
[External Code]	
System.Windows.Forms.Primitives.dll!Interop.UiaCore.UiaReturnRawElementProvider(System.Runtime.InteropServices.HandleRef hwnd, System.IntPtr wParam, System.IntPtr lParam, Interop.UiaCore.IRawElementProviderSimple el) Line 17	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ReleaseUiaProvider(System.IntPtr handle) Line 9758	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WmDestroy(ref System.Windows.Forms.Message m) Line 11852	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 12804	C#
System.Windows.Forms.dll!System.Windows.Forms.TextBoxBase.WndProc(ref System.Windows.Forms.Message m) Line 2215	C#
System.Windows.Forms.dll!System.Windows.Forms.TextBox.WndProc(ref System.Windows.Forms.Message m) Line 992	C#
System.Windows.Forms.dll!System.Windows.Forms.ToolStripTextBox.ToolStripTextBoxControl.WndProc(ref System.Windows.Forms.Message m) Line 287	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 67	C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 119	C#
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 372	C#

Note:

  • The issue is reproducible in .NET Core 5.0 and .NET Core 3.1
  • The issue is not reproducible in .NET Framework 4.7.2

@ghost ghost closed this as completed Dec 7, 2020
@RussKie RussKie reopened this Dec 7, 2020
@ghost ghost removed the 💤 no-recent-activity label Dec 7, 2020
@ghost
Copy link

ghost commented Dec 21, 2020

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.

@RussKie RussKie removed 💤 no-recent-activity 📭 waiting-author-feedback The team requires more information from the author labels Dec 21, 2020
@SergeySmirnov-Akvelon SergeySmirnov-Akvelon added the 🪲 bug Product bug (most likely) label Jan 15, 2021
@SergeySmirnov-Akvelon SergeySmirnov-Akvelon self-assigned this Jan 15, 2021
@SergeySmirnov-Akvelon SergeySmirnov-Akvelon added this to the 6.0 Preview1 milestone Jan 15, 2021
@SergeySmirnov-Akvelon SergeySmirnov-Akvelon added 💥 regression-preview Regression from a preview release tenet-accessibility MAS violation, UIA issue; problems with accessibility standards labels Jan 15, 2021
@SergeySmirnov-Akvelon
Copy link
Contributor

Simple Application

During investigation, we discovered several details:

  1. When the Form is closed and the BindingNavigator is disposed, the UiaReturnRawElementProvider command is called. In some cases, calling this command will redraw the DataGridView, resulting in an error because the DataGridView.DataConnection.CurrencyManager no longer contains data.

  2. One of the conditions for reproducing this bug is that BindingNavigator and BindingSource are in the same ComponentModel.Container. If only one of them is in the container, then the error is not reproduced. If you remove the binding to this.components in following lines then everything will work correctly

this.bindingNavigator1 = new System.Windows.Forms.BindingNavigator(this.components);
this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
  1. We think that adding a check for the fact that the DataConnection.CurrencyManager is empty or the form is now closing will not be entirely correct, because the method for redrawing the DataGridView is called quite often and additional checks can lead to a drop in performance

@RussKie RussKie modified the milestones: 6.0 Preview1, 6.0 Preview2 Jan 27, 2021
@RussKie
Copy link
Member

RussKie commented Jan 29, 2021

This suggestions look reasonable. Let's get it fixed and look at any perf implications then.

@ghost ghost added the 🚧 work in progress Work that is current in progress label Feb 10, 2021
@RussKie RussKie modified the milestones: 6.0 Preview2, 6.0 Preview3 Feb 23, 2021
vladimir-krestov added a commit to vladimir-krestov/winforms that referenced this issue Mar 2, 2021
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.
@ghost ghost removed the 🚧 work in progress Work that is current in progress label Mar 2, 2021
RussKie pushed a commit that referenced this issue Mar 2, 2021
…taSource (#4551)

to DataGridView and BindingNavigator.

Fixes #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.
@RussKie RussKie removed this from the 6.0 Preview3 milestone Mar 2, 2021
@dotnet dotnet deleted a comment Mar 2, 2021
@RussKie
Copy link
Member

RussKie commented Mar 2, 2021

@coderb how severely does this issue impact you?

@coderb
Copy link
Author

coderb commented Mar 2, 2021

@RussKie i've delayed upgrading to 5.0 (still on 3.1) due to it. it would be great if it landed in a production release sooner rather than later!

RussKie pushed a commit to RussKie/winforms that referenced this issue Mar 3, 2021
…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)
@ghost ghost added the 🚧 work in progress Work that is current in progress label Mar 3, 2021
@RussKie
Copy link
Member

RussKie commented Mar 3, 2021

We've got an approval to service this in 5.0.5

@coderb
Copy link
Author

coderb commented Mar 4, 2021

fantastic, thank you!

RussKie added a commit that referenced this issue Mar 10, 2021
…osed (servicing) (#4637)

to DataGridView and BindingNavigator.

Fixes #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)

Co-authored-by: vladimir-krestov <49272759+vladimir-krestov@users.noreply.github.com>
@ghost ghost removed the 🚧 work in progress Work that is current in progress label Mar 10, 2021
@Zheng-Li01
Copy link
Member

Verified the issue with latest 6.0.100-preview.3.21169.6, the issue has been fixed that no exception ops up for now.

@John-Qiao
Copy link
Member

Verified the issue with .NET SDK 5.0.202 from April 2021 Update Test Pass, this issue is fixed.
4216-TestResult

@ghost ghost locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Controls-DataGridView 🪲 bug Product bug (most likely) 💥 regression-preview Regression from a preview release tenet-accessibility MAS violation, UIA issue; problems with accessibility standards
Projects
None yet
6 participants