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
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
Sorry Phil;
That should be
ChildForm.Activate()
Fernando
That should be
ChildForm.Activate()
Fernando
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
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)
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?
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
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)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
Have you tried setting the
TheMDIContainer.ActivateMd
Fernando