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
TSFLLCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi Phil;

Have you tried setting the

        TheMDIContainer.ActivateMdiChild(ChildForm)

Fernando
Fernando SotoRetiredCommented:
Sorry Phil;

That should be

    ChildForm.Activate()

Fernando
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




Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

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

Yes.

myFormsList.Add(1, Me.ToString)

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



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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.