Skip to content

InvalidOperationException when dialog containing focused DataGridView is closed #13304

@chrarnoldus

Description

@chrarnoldus

.NET version

Crash repros with at least .NET 8.0.15 and .NET 10 preview 3

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

not sure which version introduced the issue, but there's no crash on .NET Framework

Issue description

When a dialog with a DataGridView that has focus is closed, an InvalidOperationException is thrown:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
   at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
   at System.Windows.Forms.DataGridView.set_CurrentCell(DataGridViewCell value)
   at System.Windows.Forms.DataGridView.OnBindingContextChanged(EventArgs e)
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

Steps to reproduce

Use the attached project and follow the following steps (the attached video shows the steps as well):

  • Start the app
  • Open the dialog with the 'Open dialog' button
  • Focus one of the inputs on the new data grid row
  • Try to close the dialog using 'X'
  • An exception is thrown, while I would have expected the dialog to close gracefully.

DataGridViewCrash.zip

DataGridViewCrash.mp4

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions