Modal Dialogs

Jun 28, 2009 at 3:17 PM

Hello, excellent work! I have checked your ContactManager sample, very nice, but all the Dialogs are modeless, i can't find any property for modality behaviour on BaseView. How can i set the dialog as modal?

Jun 30, 2009 at 1:07 PM

Hi! There isn't any property for modality behaviour on BaseView, however to resolve your problem you can override the BaseView's DisplayView() method. By default the framework invoke the Show() method of a specific view (through DisplayView()), by overriding the DisplayView method you can replace xxxForm.Show() by the build in fonction xxxForm.ShowDialog(), an example is shown below

public override void DisplayView()


    this.BindDataToView();  //This method is very important

    if (this.Visible == false) this.ShowDialog();


I think that this solution is appropriate for your problem. We can go further by adding a property modality behaviour (as you suggest) on the BaseView, and depending on that property a specific dialogs can be modeless or not (i mean a specific view can be displayed as a dialog or not).

Thank you for the idea!!!!

Aug 13, 2010 at 1:15 PM

I don't know if the koossery.MVCwin project is still alive, but I'll try anyway.

In many Windows Forms application modal dialogs are used in a way like this:

You have some MainForm from which you might want to open a SettingsForm. Doing so results in the SettingsForm opening on top of the MainForm while inhibiting interaction with the MainForm. When exiting the SettingsForm control is transferred back to the MainForm.

The suggested solution regarding modal dialogs in koossery.MVCwin doesn't solve this for two reasons:

  • It will show the SettingsForm as modal, but the MainForm will be hidden, so you don't get the SettingsForm on top of the MainForm
  • If there is multiple ways of showing the SettingsForm (let's say it can be showed from MainForm and SomeOtherForm) then it seems there is no way of knowing from which form the SettingsForm was invoked.

It may be I'm missing some knowledge about koossery.MVCwin usage, so that I don't use it properly. But I haven't figured out how to solve the scenario above.

Does anyone know of a viable solution?

Aug 13, 2010 at 4:41 PM

Hi! Yes the project is still alive and we are about to upload the next version and the associated tutorials.

1/ Let say if you want your MainForm (this solution is specific to the Mainform) to always be displayed, then you can override the HideView() method and leave it that way. Then the koossery.MVCwin won't be able to hide that form anymore.

2/ If you want the previous form to still be displayed (of course you can use the first solution) then set the IsChildForm (boolean property) of that view to false. Doing it that way will prevent the view to be hidden. Whenever that property is set to false then koossery.MVCwin won't invoke the HideView() method of that view. Let say you invoke SettingsForm from SomeOtherForm and you want SomeOtherForm to still be displayed then set the IsChildForm of SomeOtherForm to false.

3/ If you want to know from which form the SettingsForm is invoked, then you have to it manually because right now koossery.MVCwin does not provide an automatic way to do it. You can follow those steps to do it manually.

  • Add a string PreviousView property in SettingsFormViewData.
  • Before invoking the Controller that displays the SettingsForm, retrieve SettingsFormViewData using GetSessionData(key)
  • Set the PreviousView to the current one from wich you are invoking SettingsForm

Using the scenario you discribed above, we can go further by adding an automatic build in function that provide the developper with those important information. Thank you for your suggestion. Feel free to post again if you have another problem.



Aug 23, 2010 at 8:45 AM

Thank you for your detailed answer. It's nice to hear the project is still alive, and I'm looking forward to the upcoming release.

I didn't get the modal dialog on top of another dialog to work by setting the IsChildForm property to false. However, by overriding HideView() in MainForm and overriding DisplayView() in SettingsForm using mohamadou's suggestion I was able to obtain the wanted result. There is only a minor thing: when closing the SettingsForm the MainForm will quickly hide and then show again, kind of like a blink. But I guess I can live with that.

So to sum up, in MainForm I did this:

public override void HideView()
{ }

In SettingsForm I did this:

public override void DisplayView()
     if (this.Visible == false) this.ShowDialog();

The 3rd point regarding a previous view property seems to be a fine solutions, and if you build it into the framework even better :)