Results 1 to 11 of 11

Thread: Using ShowDialog

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    14

    Using ShowDialog

    I'm having problems using dialog windows in my program. Specifically when I call a
    window using the ShowDialog in an SDI environment.

    I have a main form that calls a dialog:

    VB Code:
    1. dim frm as new frmMaps
    2. frm.ShowDialog


    in frmMaps I have 2 buttons that call another dialog (Add/Edit)

    VB Code:
    1. dim frm as new frmEditMap
    2. frm.ShowDialog


    Problem arrises when I click close on the frmEditMap:

    VB Code:
    1. Me.DialogResult = DialogResult.Cancel
    2.     Me.Close


    However, for some reason this also closes the parent, frmMaps.
    Essentially my goal is to have only once instance of frmMaps.


    Cheers,

    Tom
    Cheers,

    Black Thunder

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    How did you create the instance of the Main Form?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    14
    dim f as new frmMain
    Application.Run(f)
    Cheers,

    Black Thunder

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Sorry I misread your original post.

    You have used the variable "Frm" to hold the instance of frmMaps AND then replaced it with frmEditMap. Change the instance name of one of them to frm1.

    If in run mode you move the form which is "on top" i.e. the instance of frmEditMap, you will find that the instance of frmMaps has already been closed.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    14
    Those variables are declared within each function, I didn't think they were shared out of scope.

    Cheers,
    Cheers,

    Black Thunder

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by BlackThunder
    Those variables are declared within each function, I didn't think they were shared out of scope.

    Cheers,
    The effect is the same, once they go out of scope they are destroyed.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    If I well understand (always I have to premit this consideration )the button you use to instance your child form has property DialogResult not set to 'None'. So when the child form close and code in parent's button click procedure can come to its end it close itself, too. I say this assuming your parent form is modally showed, too. If not forgive all!
    Live long and prosper (Mr. Spock)

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    14
    It would seem that settings

    Me.DialogResult = DialogResult.None

    at the end of the button code works, what an odd implementation tho.
    Cheers,

    Black Thunder

  9. #9
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Uhmmm, obviously it's possible there is another reason, but what I'm trying to check is if the property of button in your Parent form is set to dialogresult=none. You can check it at design mode. I'm not sure to have understood where the code 'Me.DialogResult = DialogResult.None' is placed, but you need only to test the button's property from property window and you can have a confirm or not. If the parent's button has property setted to something different then 'None' it will close your parent Form at the end of its routine....only if your parent is modal, obviously. If not.....sorry!

    Live long and prosper (Mr. Spock)

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    14
    here's the breakdown of the code


    in frmMain

    VB Code:
    1. Private Sub mnuFavorite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFavorite.Click
    2.         Dim fmaps As New frmMaps
    3.         fmaps.ShowDialog()
    4.     End Sub

    in frmMaps

    VB Code:
    1. Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
    2.         Dim fe As New frmEditMap
    3.         Dim map As clsMap
    4.         fe.Init()
    5.  
    6.         If fe.ShowDialog = DialogResult.OK Then
    7.             map = New clsMap
    8.             map.Map = fe.txtMap.Text
    9.             map.Game = fe.cmbGames.Text
    10.             map.CaseSensitive = fe.chkCase.Checked
    11.             map.PartialMatch = fe.chkPartial.Checked
    12.             map.ID = maps.Count
    13.             maps.Add(map)
    14.         End If
    15.  
    16.         fe.Dispose()
    17.         fe = Nothing
    18.  
    19.         Renumber()
    20.         Populate()
    21.  
    22.         Me.DialogResult = DialogResult.None
    23.  
    24.     End Sub



    in frmEditMap

    VB Code:
    1. Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
    2.         Me.DialogResult = DialogResult.OK
    3.         Me.Close()
    4.     End Sub
    Cheers,

    Black Thunder

  11. #11
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    I've tried some simulations, but your code seems correct. The only thing remains to check is if your FrmMaps is hidden by a procedure. To Hide a Modal Form cause it return also with dialogresult = none. If not, I hope a more experienced friend will help you! Good luck and good job!
    Live long and prosper (Mr. Spock)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width