C# / .NET 3.5 / WinForms
I’ve got a form that opens a modal dialog form which opens another modal dialog form. The inner dialog form has OK and Cancel buttons and its AcceptButton and CancelButton are set to them respectively.
When I hit Enter or click OK in the inner dialog, the outer dialog closes as well. I can’t see where I’m doing this – is this expected behaviour?
I can supply code but I didn’t want to clutter this up.
This happens because a
ShowDialogcall modifies its owner’s state as well.To prevent this from happening, you need to reset the
DialogResultof the first modal dialog toDialogResult.Noneafter theShowDialogcall to the second dialog:This has been a long-standing issue (see this post).