locked
custom modal window RRS feed

  • Question

  • Hi there,

    I am trying to use custom modal window in my project.

    I have this helper class by Yann copied in my application code (client) part.

    Now, when I create new modal window and create new button, for example DialogOK, then when I am going to edit execute code, intellitype offers me DialogOK(), DialogOK_Execute and so on.

    But if I create button with code DialogOK(), or Me.DialogOK(), then it is not working. It says "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll".

    What am I doing wrong?

    Or, I want to create new button for viewing and editing selected entity. In helper class, there is public sub ViewEntity(). How I can do that? When I create new method called ViewEntity and edit execute code, i can see ViewEntity(), but again same error when running app.

    Obviously, I am missing something basic.

    Do I need to write some code at InitializeDataWorkspace? If yes, can you please show me that in VB please?

    Thank You



    • Edited by eMCeee89 Wednesday, April 3, 2013 9:43 PM
    Wednesday, April 3, 2013 9:27 PM

Answers

  • eMCeee89,

    This is how I have it implemented and it seems to work for me.  I hope it helps.  You could do what you are suggesting, but Yann's Helper class does it for you.

    Private Sub myProfile_InitializeDataWorkspace(saveChangesTo As List(Of IDataService))
                myAddEditSkill = New ModalWindowHelper(Me.InventoryDetails, "CustomAddandEdit")
    ...
    Private Sub myProfile_Created()
                myAddEditSkill.Initialize(hasCloseButton:=True, saveOnClose:=True)
    End Sub
    ...
    Private Sub InventoryDetailsEditSelected_Execute()
               myAddEditSkill.ViewEntity()
    ...
    Private Sub AddEditSkillOk_Execute()
       If Me.Details.ValidationResults.HasErrors = False Then
             Me.CloseModalWindow("CustomAddandEdit")
       End If
    End Sub
    ...
    Private Sub AddEditSkillCancel_Execute()
                Me.CloseModalWindow("CustomAddandEdit")
    End Sub

    My screen is myProfile.  My modal window is CustomAddandEdit.  My Ok button is called:  AddEditSkillOk and my Cancel button is called AddEditSkillCancel.  On my datagrid, I did an "override code" to force my modal window to appear instead of the standard window and  it is called InventoryDetailsEditSelected.   

    I hope this helps you.

    Jennifer

    • Marked as answer by eMCeee89 Monday, April 8, 2013 2:20 PM
    Sunday, April 7, 2013 5:17 PM
  • Things like ViewEntity, AddEntity, DeleteEntity should be called from a screen button's Execute method. DialogOK & DialogCancel are meant to be called from the Save & Cancel button that you add to the modal window.

    "I have one more question about modal window helper class. What are the benefits of using it"

    You don't need my class to work with modal windows, but as Jennifer pointed out, it does a lot of the "work" for you, so you write less repetitive code.

    "Do I need to write some code at InitializeDataWorkspace?"

    Yes, absolutely. You have to call the modalWindowName.Initialise method in InitializeDataWorkspace.

    To be getting the stackoverflow error, you're probably causing code to execute recursively. Use the method the way I just described, & it should work fine. One of these days I REALLY have to get around to writing better documentation for the ModalWindow class.


    Yann - LightSwitch Central
    Luminous Tools for LightSwitch (a FREE productivity extension)
    FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer", if any reply answers your question.
    Please click "Vote as Helpful", if you find any reply helpful.
     
    By doing this you'll help others to find answers faster.

    • Marked as answer by eMCeee89 Monday, April 8, 2013 2:20 PM
    Monday, April 8, 2013 3:21 AM
    Moderator

All replies

  • If you dont mind, I have one more question about modal window helper class.

    What are the benefits of using it.

    Why should I call DialogOK() method instead of writing code:

    Me.CloseModalWindow("ModalWindowName")

    or, method DialogCancel() method instead of:

    Me.Entity.SelectedItem.Details.DiscardChanges()
    Me.CloseModalWindow("ModalWindowName")

    It is just a little bit more code, so it doesnt matter.

    Thank you

    Thursday, April 4, 2013 11:54 AM
  • eMCeee89,

    This is how I have it implemented and it seems to work for me.  I hope it helps.  You could do what you are suggesting, but Yann's Helper class does it for you.

    Private Sub myProfile_InitializeDataWorkspace(saveChangesTo As List(Of IDataService))
                myAddEditSkill = New ModalWindowHelper(Me.InventoryDetails, "CustomAddandEdit")
    ...
    Private Sub myProfile_Created()
                myAddEditSkill.Initialize(hasCloseButton:=True, saveOnClose:=True)
    End Sub
    ...
    Private Sub InventoryDetailsEditSelected_Execute()
               myAddEditSkill.ViewEntity()
    ...
    Private Sub AddEditSkillOk_Execute()
       If Me.Details.ValidationResults.HasErrors = False Then
             Me.CloseModalWindow("CustomAddandEdit")
       End If
    End Sub
    ...
    Private Sub AddEditSkillCancel_Execute()
                Me.CloseModalWindow("CustomAddandEdit")
    End Sub

    My screen is myProfile.  My modal window is CustomAddandEdit.  My Ok button is called:  AddEditSkillOk and my Cancel button is called AddEditSkillCancel.  On my datagrid, I did an "override code" to force my modal window to appear instead of the standard window and  it is called InventoryDetailsEditSelected.   

    I hope this helps you.

    Jennifer

    • Marked as answer by eMCeee89 Monday, April 8, 2013 2:20 PM
    Sunday, April 7, 2013 5:17 PM
  • Things like ViewEntity, AddEntity, DeleteEntity should be called from a screen button's Execute method. DialogOK & DialogCancel are meant to be called from the Save & Cancel button that you add to the modal window.

    "I have one more question about modal window helper class. What are the benefits of using it"

    You don't need my class to work with modal windows, but as Jennifer pointed out, it does a lot of the "work" for you, so you write less repetitive code.

    "Do I need to write some code at InitializeDataWorkspace?"

    Yes, absolutely. You have to call the modalWindowName.Initialise method in InitializeDataWorkspace.

    To be getting the stackoverflow error, you're probably causing code to execute recursively. Use the method the way I just described, & it should work fine. One of these days I REALLY have to get around to writing better documentation for the ModalWindow class.


    Yann - LightSwitch Central
    Luminous Tools for LightSwitch (a FREE productivity extension)
    FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer", if any reply answers your question.
    Please click "Vote as Helpful", if you find any reply helpful.
     
    By doing this you'll help others to find answers faster.

    • Marked as answer by eMCeee89 Monday, April 8, 2013 2:20 PM
    Monday, April 8, 2013 3:21 AM
    Moderator
  • Hey guys,

    thank you for your replies. Meanwhile, I left helper class and solved my task with code in my post up there.

    Now, I am creating reports with DevExpress extension, but I will definitely have a look at helper class when done with those reports.

    Thank both of you again.

    Monday, April 8, 2013 2:25 PM
  • I noticed a mistake in the code I copied .. :-(    My apologies.   Good luck!!

    Private Sub EditSkillOk_Execute()
       If Me.Details.ValidationResults.HasErrors = False Then
         myEditSkill.DialogOk()
       End If
    End Sub
    ...
    Private Sub EditSkillCancel_Execute()
      myEditSkill.DialogCancel()
    End Sub

    Monday, April 8, 2013 2:46 PM