Link to home
Start Free TrialLog in
Avatar of TSFLLC
TSFLLC

asked on

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
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi Phil;

Have you tried setting the

        TheMDIContainer.ActivateMdiChild(ChildForm)

Fernando
Sorry Phil;

That should be

    ChildForm.Activate()

Fernando
Avatar of TSFLLC
TSFLLC

ASKER

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




Hay Phil, are you storing the CriteriaForm object in the TashTable as well?
Avatar of TSFLLC

ASKER


Yes.

myFormsList.Add(1, Me.ToString)

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



ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TSFLLC

ASKER

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?