From: wesch on
May be the problem comes only from my misunderstanding of how to use forms
for dialogs.
I want to have a dialog I can accept or cancel. And I want to do some
validating on the form level.

I know in WM there is only the "OK" on the upper right corner. So I have to
put two buttons "Accept" and "Cancel" on the form. May be here is the first
mistake I make, I decided to have two menu items for accept and cancel.

Here are the problems I have.

I use databinding to bind the control properties to some form properties.
Closing the form by pressing the OK-Button doesn't free the focus from the
current selected control, so databinding doesn't work. Focus the form in
Closing event, as someone suggested, also doesn't help. The only way I found
is to call the controls BindingManagerBase.EndCurrentEdit(). Is there e
better way?

Next, pressing the OK-Button fires the Closing event and I can do form
validation. But closing the form from the menu items by calling the Close
method of the form, fires the Closing event twice. Is the another way to
close the dialog form than by calling the Close method?

The last problems comes with the previous. As I found out that the Closing
event is fired twice, I tried to skip one, because I want to bring up a
MessageBox while validating, which shouldn't be shown twice. In case of
prevent from closing I have to set the event handler argument to Cancel. But
it doesn't matter if I do this for the first or second call of the Closing
event, I have to do this for both. Only in this case it works.

All these problems makes it very difficult to have an assumed dialog
behaviour. So I assume I'm doing something wrong. Can someone point me to ma
mistakes?

Thanks