473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Accessing parent controls in an MDI form fom the child forms by their name

I hav two queries, whc are as follows:
FIRSTLY:
is it possible to access the controls(by name) of a parent form(MDI)
from its child forms??if yes then how??plzz provide a coded example in
VB if possible..

for example..i hav a menu in the parent form named "Administrator" whic
has an item "mnuLogIn"..now when i click on login..another child form
named "frmLogIn" is displayed..what i want to happen is this:
when login form(frmLogIn) is opened, the corresponding menu option in
the parent form (i.e menu option "mnuLogIn") should get disabled..and
when i close the "frmLogIn" child form..the menu item "mnuLogIn" in the
parent form should again be enabled.

so..what shud i write in the child form's(frmLogIn's) "closed" event
and "load" event..so tht it enables and disbles the corresponding menu
item(mnuLogIn) in the parent form's menu on these two events
respectively??

I ALREADY KNOW HOW TO DO THIS USING THE INDEX OF THE PARENT MENU
ITEM(i.e. by using Me.ParentForm.Menu.MenuItems(0).Enabled = False
...etc..)..but i want a way in whc i can access those menu items by
name..for example if the parent form's menu item's name is "mnuLogIn" ,
then i want to access it by the same name in the child form so that i
can chage the properties of the item in the parent form.is it
possible??if yes..i want the coded solution..if not,then why??
SECONDLY:
i hav an xml file whc has some database connectivity parameters, how
can i access them in a VB windows form??i mean how can i access data in
xml files in windows application?
suppose i hav the <connection string, <database nameetc..as xml
values in an xml file..and i want tht evrytime i create a
connection/make a transaction, my applications reads these connection
parameters from this xml file instead of i specifying that in code and
establishes the connection/executes the query...can any1 show in VB
code how to do that??can any1 suggest a better way to store this
information in any other file other than XML..say in a text file..and
then the application can access and read necessary data by searching
for it in the file?

i hope some1 will take his time, interest and effort to answer my
queries..whc might be very easy for many..thanx
Raj

Jul 4 '06 #1
4 3587
Raj,

About your first question.

I don't think what you suggest is a good idea. Accessing these menu item by
name would be late bound, so that typing mistakes for example would only be
detected at runtime and not at compile time. Also, your login screen would
not be usable without your main screen, for exmpla if you want to reuse it in
your next project.

I would suggest two possible solutions:
- show your login dialog as a modal dialog (frmLogin.ShowDialog). This
prevents accessing all other forms and their controls while your login form
is visible.
-or disable your menu item in its own click-event-handler, and then handle
the closed event of your login-form in your main-form. Something like this
(typed in the editor, so there could be some typing errors):

Private Sub mnuLogin_Click(...)
dim f as new frmLogin
f.Owner = Me
f.Show
mnuLogin.Enabled = False
AddHandler f.Closed, AddressOf LoginFormClosed
End Sub

Private Sub LoginFormClosed(sender as object, e as eventargs)
RemoveHandler directcast(sender, form).Closed, AddressOf LoginFormClosed
mnuLogin.Enabled = True
End Sub

Hope this helps,

Joris
"raj_genius" wrote:
I hav two queries, whc are as follows:
FIRSTLY:
is it possible to access the controls(by name) of a parent form(MDI)
from its child forms??if yes then how??plzz provide a coded example in
VB if possible..

for example..i hav a menu in the parent form named "Administrator" whic
has an item "mnuLogIn"..now when i click on login..another child form
named "frmLogIn" is displayed..what i want to happen is this:
when login form(frmLogIn) is opened, the corresponding menu option in
the parent form (i.e menu option "mnuLogIn") should get disabled..and
when i close the "frmLogIn" child form..the menu item "mnuLogIn" in the
parent form should again be enabled.

so..what shud i write in the child form's(frmLogIn's) "closed" event
and "load" event..so tht it enables and disbles the corresponding menu
item(mnuLogIn) in the parent form's menu on these two events
respectively??

I ALREADY KNOW HOW TO DO THIS USING THE INDEX OF THE PARENT MENU
ITEM(i.e. by using Me.ParentForm.Menu.MenuItems(0).Enabled = False
...etc..)..but i want a way in whc i can access those menu items by
name..for example if the parent form's menu item's name is "mnuLogIn" ,
then i want to access it by the same name in the child form so that i
can chage the properties of the item in the parent form.is it
possible??if yes..i want the coded solution..if not,then why??
SECONDLY:
i hav an xml file whc has some database connectivity parameters, how
can i access them in a VB windows form??i mean how can i access data in
xml files in windows application?
suppose i hav the <connection string, <database nameetc..as xml
values in an xml file..and i want tht evrytime i create a
connection/make a transaction, my applications reads these connection
parameters from this xml file instead of i specifying that in code and
establishes the connection/executes the query...can any1 show in VB
code how to do that??can any1 suggest a better way to store this
information in any other file other than XML..say in a text file..and
then the application can access and read necessary data by searching
for it in the file?

i hope some1 will take his time, interest and effort to answer my
queries..whc might be very easy for many..thanx
Raj

Jul 5 '06 #2
Hello, Raj,

To access a control by name I think that you will have to search
(recursively) through all controls until you find the one(s) that match
the name you want.

To accomplish your ultimate goal (enabling/disabling menu items based on
the current state of the application) I suggest that you reverse the
responsibility. I.e. put the code to enable/disable child menu items in
a handler for the parent menu's Popup event.

Cheers,
Randy
raj_genius wrote:
I hav two queries, whc are as follows:
FIRSTLY:
is it possible to access the controls(by name) of a parent form(MDI)
from its child forms??if yes then how??plzz provide a coded example in
VB if possible..

for example..i hav a menu in the parent form named "Administrator" whic
has an item "mnuLogIn"..now when i click on login..another child form
named "frmLogIn" is displayed..what i want to happen is this:
when login form(frmLogIn) is opened, the corresponding menu option in
the parent form (i.e menu option "mnuLogIn") should get disabled..and
when i close the "frmLogIn" child form..the menu item "mnuLogIn" in the
parent form should again be enabled.

so..what shud i write in the child form's(frmLogIn's) "closed" event
and "load" event..so tht it enables and disbles the corresponding menu
item(mnuLogIn) in the parent form's menu on these two events
respectively??

I ALREADY KNOW HOW TO DO THIS USING THE INDEX OF THE PARENT MENU
ITEM(i.e. by using Me.ParentForm.Menu.MenuItems(0).Enabled = False
..etc..)..but i want a way in whc i can access those menu items by
name..for example if the parent form's menu item's name is "mnuLogIn" ,
then i want to access it by the same name in the child form so that i
can chage the properties of the item in the parent form.is it
possible??if yes..i want the coded solution..if not,then why??
SECONDLY:
i hav an xml file whc has some database connectivity parameters, how
can i access them in a VB windows form??i mean how can i access data in
xml files in windows application?
suppose i hav the <connection string, <database nameetc..as xml
values in an xml file..and i want tht evrytime i create a
connection/make a transaction, my applications reads these connection
parameters from this xml file instead of i specifying that in code and
establishes the connection/executes the query...can any1 show in VB
code how to do that??can any1 suggest a better way to store this
information in any other file other than XML..say in a text file..and
then the application can access and read necessary data by searching
for it in the file?

i hope some1 will take his time, interest and effort to answer my
queries..whc might be very easy for many..thanx
Raj
Jul 5 '06 #3
well..thanx 14 ur reply..actually i am not using login form from the
menu...the login form is a separate standalone form and when it is
opened..no other forsm is active...i just mentioned it as an
example.see..my problem is I HAVE TO ACCESS THE PARENT'S MENU ITEMS BY
NAME..so..it wud be great if some1 can tell me how to do that
Joris Zwaenepoel wrote:
Raj,

About your first question.

I don't think what you suggest is a good idea. Accessing these menu item by
name would be late bound, so that typing mistakes for example would only be
detected at runtime and not at compile time. Also, your login screen would
not be usable without your main screen, for exmpla if you want to reuse it in
your next project.

I would suggest two possible solutions:
- show your login dialog as a modal dialog (frmLogin.ShowDialog). This
prevents accessing all other forms and their controls while your login form
is visible.
-or disable your menu item in its own click-event-handler, and then handle
the closed event of your login-form in your main-form. Something like this
(typed in the editor, so there could be some typing errors):

Private Sub mnuLogin_Click(...)
dim f as new frmLogin
f.Owner = Me
f.Show
mnuLogin.Enabled = False
AddHandler f.Closed, AddressOf LoginFormClosed
End Sub

Private Sub LoginFormClosed(sender as object, e as eventargs)
RemoveHandler directcast(sender, form).Closed, AddressOf LoginFormClosed
mnuLogin.Enabled = True
End Sub

Hope this helps,

Joris
"raj_genius" wrote:
I hav two queries, whc are as follows:
FIRSTLY:
is it possible to access the controls(by name) of a parent form(MDI)
from its child forms??if yes then how??plzz provide a coded example in
VB if possible..

for example..i hav a menu in the parent form named "Administrator" whic
has an item "mnuLogIn"..now when i click on login..another child form
named "frmLogIn" is displayed..what i want to happen is this:
when login form(frmLogIn) is opened, the corresponding menu option in
the parent form (i.e menu option "mnuLogIn") should get disabled..and
when i close the "frmLogIn" child form..the menu item "mnuLogIn" in the
parent form should again be enabled.

so..what shud i write in the child form's(frmLogIn's) "closed" event
and "load" event..so tht it enables and disbles the corresponding menu
item(mnuLogIn) in the parent form's menu on these two events
respectively??

I ALREADY KNOW HOW TO DO THIS USING THE INDEX OF THE PARENT MENU
ITEM(i.e. by using Me.ParentForm.Menu.MenuItems(0).Enabled = False
...etc..)..but i want a way in whc i can access those menu items by
name..for example if the parent form's menu item's name is "mnuLogIn" ,
then i want to access it by the same name in the child form so that i
can chage the properties of the item in the parent form.is it
possible??if yes..i want the coded solution..if not,then why??
SECONDLY:
i hav an xml file whc has some database connectivity parameters, how
can i access them in a VB windows form??i mean how can i access data in
xml files in windows application?
suppose i hav the <connection string, <database nameetc..as xml
values in an xml file..and i want tht evrytime i create a
connection/make a transaction, my applications reads these connection
parameters from this xml file instead of i specifying that in code and
establishes the connection/executes the query...can any1 show in VB
code how to do that??can any1 suggest a better way to store this
information in any other file other than XML..say in a text file..and
then the application can access and read necessary data by searching
for it in the file?

i hope some1 will take his time, interest and effort to answer my
queries..whc might be very easy for many..thanx
Raj
Jul 5 '06 #4
Unfortunatly it looks like menuItem objects do not have a "Name" property, so
I cannot help you with that.

With reflection you may be able to get this working, but I do not know
enough about it to be able to help you with that.

Joris

"raj_genius" wrote:
well..thanx 14 ur reply..actually i am not using login form from the
menu...the login form is a separate standalone form and when it is
opened..no other forsm is active...i just mentioned it as an
example.see..my problem is I HAVE TO ACCESS THE PARENT'S MENU ITEMS BY
NAME..so..it wud be great if some1 can tell me how to do that
Joris Zwaenepoel wrote:
Raj,

About your first question.

I don't think what you suggest is a good idea. Accessing these menu item by
name would be late bound, so that typing mistakes for example would only be
detected at runtime and not at compile time. Also, your login screen would
not be usable without your main screen, for exmpla if you want to reuse it in
your next project.

I would suggest two possible solutions:
- show your login dialog as a modal dialog (frmLogin.ShowDialog). This
prevents accessing all other forms and their controls while your login form
is visible.
-or disable your menu item in its own click-event-handler, and then handle
the closed event of your login-form in your main-form. Something like this
(typed in the editor, so there could be some typing errors):

Private Sub mnuLogin_Click(...)
dim f as new frmLogin
f.Owner = Me
f.Show
mnuLogin.Enabled = False
AddHandler f.Closed, AddressOf LoginFormClosed
End Sub

Private Sub LoginFormClosed(sender as object, e as eventargs)
RemoveHandler directcast(sender, form).Closed, AddressOf LoginFormClosed
mnuLogin.Enabled = True
End Sub

Hope this helps,

Joris
"raj_genius" wrote:
I hav two queries, whc are as follows:
FIRSTLY:
is it possible to access the controls(by name) of a parent form(MDI)
from its child forms??if yes then how??plzz provide a coded example in
VB if possible..
>
for example..i hav a menu in the parent form named "Administrator" whic
has an item "mnuLogIn"..now when i click on login..another child form
named "frmLogIn" is displayed..what i want to happen is this:
when login form(frmLogIn) is opened, the corresponding menu option in
the parent form (i.e menu option "mnuLogIn") should get disabled..and
when i close the "frmLogIn" child form..the menu item "mnuLogIn" in the
parent form should again be enabled.
>
so..what shud i write in the child form's(frmLogIn's) "closed" event
and "load" event..so tht it enables and disbles the corresponding menu
item(mnuLogIn) in the parent form's menu on these two events
respectively??
>
I ALREADY KNOW HOW TO DO THIS USING THE INDEX OF THE PARENT MENU
ITEM(i.e. by using Me.ParentForm.Menu.MenuItems(0).Enabled = False
...etc..)..but i want a way in whc i can access those menu items by
name..for example if the parent form's menu item's name is "mnuLogIn" ,
then i want to access it by the same name in the child form so that i
can chage the properties of the item in the parent form.is it
possible??if yes..i want the coded solution..if not,then why??
>
>
SECONDLY:
i hav an xml file whc has some database connectivity parameters, how
can i access them in a VB windows form??i mean how can i access data in
xml files in windows application?
suppose i hav the <connection string, <database nameetc..as xml
values in an xml file..and i want tht evrytime i create a
connection/make a transaction, my applications reads these connection
parameters from this xml file instead of i specifying that in code and
establishes the connection/executes the query...can any1 show in VB
code how to do that??can any1 suggest a better way to store this
information in any other file other than XML..say in a text file..and
then the application can access and read necessary data by searching
for it in the file?
>
i hope some1 will take his time, interest and effort to answer my
queries..whc might be very easy for many..thanx
Raj
>
>

Jul 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brindley | last post by:
Hi there, In my Mdi application, I have placed a set of controls on the parent form to call child forms. The problem is that the controls hide the child forms. I have used SendToBack when Im...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
6
by: Claus Holm | last post by:
I'm trying to enable a menuitem in the parent form from a mdichild. Rather than making the menuitems public, I'd go for a public method in the parent form to do the change, but when I call the...
3
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI...
6
by: Edwinah63 | last post by:
Hi everyone, could someone give me some thoughts on the best way to manage mdi parent and child forms? in vb6 i could scroll through the forms collection and determine which forms were...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
2
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the...
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
4
by: nottarealaddress | last post by:
I'm trying to get my feet wet in VB2005 (our new standard at work after officially stopping new development in VB6 about a month ago). I'm working with a simple sql 2005 table of 50 entries, one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.