• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Topmost issue on activated forms

I have an issue with currently activated forms not displaying on top when menu option is clicked again.

MainMenuForm
Contains my main menu
IsMDIContainer = true

CriteriaForm
It is activated from menu option on MainMenuForm with the following code:

Dim frm As New CriteriaForm
frm.MdiParent = Me
frm.Show()

DataEntryForm - Specific Table Data Entry Form
It is shown from double-click of record on datagrid from CriteriaForm with the following code:

Dim frm As New DataEntryForm
frm.MdiParent = Me.MdiParent
frm.Show()

This is how I would like the flow of things to go:

If both CriteriaForm and DataEntryForm are open and DataEntryForm is on top, I would like for
the menu option click to show the CriteriaForm to cause it to be on top of the DataEntryForm.
Likewise, if I double-click on a row of the datagrid on CriteriaForm I would like for the DataEntryForm
to return to the top at which time I would change the rowdata displayed on the form.

I also have a button on the DataEntryForm that I would like to enter on_click code into to show
the CriteriaForm back on top.

I can't use 'Dim frm As """NEW""" CriteriaForm or DataEntryForm because needless to say I get
multiple instances of the form already displayed.

I've tried options like TopMost to no avail.  I also read another thread from the form regarding
setting focus to the Criteria Form....to no avail.  I'm assuming that the parent/child relationship
between these three forms is the issue.

Is it possible to set the MainMenuForm as the MDIContainer & parent of all other forms in my
application and control them programmatically?  If not how do I resolve this problem with the
current setup of my code?

Thanks,

Phil
0
TSFLLC
Asked:
TSFLLC
  • 5
  • 3
1 Solution
 
Fernando SotoRetiredCommented:
Hi Phil;

Have you tried setting the

        TheMDIContainer.ActivateMdiChild(ChildForm)

Fernando
0
 
Fernando SotoRetiredCommented:
Sorry Phil;

That should be

    ChildForm.Activate()

Fernando
0
 
TSFLLCAuthor Commented:
Fernando,

Yes I have tried ChildForm.activate().  This is my on_click code to identify whether the form
I want to show on top is activated and then attempt to move it to the top:


myFormsList is a HashTable with a unique key for each form.

From MainMenuForm:

        If myFormsList.ContainsKey(1) Then
            Dim frm As Form = CriteriaForm.ActiveForm
            frm.Activate()
        Else
            Dim frm As New CriteriaForm
            frm.MdiParent = Me
            glTable = "form_letter"
            frm.Show()
        End If




0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Fernando SotoRetiredCommented:
Hay Phil, are you storing the CriteriaForm object in the TashTable as well?
0
 
TSFLLCAuthor Commented:

Yes.

myFormsList.Add(1, Me.ToString)

0
 
Fernando SotoRetiredCommented:
Phil;

It would be better to store the object itself in the HastTable, something like this.

Dim cf As New CriteriaForm()
myFormsList.Add(1, cf)

then when you check to see if it is already active you can do this.

        If myFormsList.ContainsKey(1) Then
            Dim cf As CriteriaForm = CType(myFormsList(1), CriteriaForm)
            cf.Activate()
        Else
            Dim frm As New CriteriaForm
            frm.MdiParent = Me
            glTable = "form_letter"
            frm.Show()
        End If

What I  think is happening is that you may be losing the reference to the CriteriaForm object because it looks like you are declaring it as a local variable and when it goes out of scope the reference is gone. Try it this way and see.

Fernando



0
 
Fernando SotoRetiredCommented:
A correction to the code I just posted.

        If myFormsList.ContainsKey(1) Then
            Dim cf As CriteriaForm = CType(myFormsList(1), CriteriaForm)
            cf.Activate()
        Else
            Dim frm As New CriteriaForm
            frm.MdiParent = Me
            myFormsList.Add(1, frm)  '<- Add object to the HashTable
            glTable = "form_letter"
            frm.Show()
        End If

Fernando
0
 
TSFLLCAuthor Commented:
Fernando

It worked like a charm!  You are the man!

The added code that you just posted regarding the myFormsList.Add....
I was adding that command line in the On_Load of the subsequent form because if
for some reason it errored on load I wouldn't have to deal with it.

I guess you should have a Try,Catch,End Try all over the place to handle errors?
I could do this on load and remove the entry to the hashtable?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now