Docking/MDI for Windows Forms Forum

Posted 19 years ago by tobias weltner
When I call "CloseAllActiveDocuments" in response to a form close event, all child docs are closing...good.
However, if the user cancels the close by pressing Cancel in the WindowClosing event (setting e.Cancel to true), this child window will not close BUT the closing process itself continues to close the remaining child windows.

Would it be possible to add a cancel method for the CloseAllActiveDocuments-process? Or would I have to replace CloseAllActiveDocuments with a loop and closing the child docs manually one by one? I tried this, too, but since closing a doc will modify the document collection, I cannot use a loop.

In other words, which is the best way to close all documents while still allowing the user to cancel the operation?

Comments (2)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Tobias,

Typically for a form close, it's good app design to present a list of the unsaved documents before any of them are closed. Then the user can choose which to save on that form.

However if you would still like to handle it the way you are, you can do a loop but you have to do it in reverse, which is what we do in our CloseAllActiveDocuments code:
for (int index = ActiveDocuments.Count - 1; index >= 0; index--)
That way you don't run into issues when items are removed from the collection. Hope that helps.

Actipro Software Support

Posted 19 years ago by tobias weltner

In the meantime, I found another way. I use a global flag, and once a user cancels, it is set to true. In the Closing event of each doc, if the flag is set it sets e.cancel = true. Works just the way I want it, and I can continue using CloseAllActiveDocuments...
The latest build of this product (v24.1.0) was released 4 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.