PC Review


Reply
Thread Tools Rate Thread

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

 
 
raj_genius
Guest
Posts: n/a
 
      4th Jul 2006
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 name> etc..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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9yaXMgWndhZW5lcG9lbA==?=
Guest
Posts: n/a
 
      5th Jul 2006
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 name> etc..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
>
>

 
Reply With Quote
 
R. MacDonald
Guest
Posts: n/a
 
      5th Jul 2006
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 name> etc..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
>

 
Reply With Quote
 
raj_genius
Guest
Posts: n/a
 
      5th Jul 2006
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 name> etc..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
> >
> >


 
Reply With Quote
 
=?Utf-8?B?Sm9yaXMgWndhZW5lcG9lbA==?=
Guest
Posts: n/a
 
      5th Jul 2006
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 name> etc..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
> > >
> > >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing the MDI parent form controls from child forms krishnasamaga Microsoft Dot NET Framework Forms 0 30th May 2006 07:25 AM
Accessing the controls on a Child form from the MDI parent Mac via DotNetMonster.com Microsoft VB .NET 0 25th Aug 2005 06:58 AM
Accessing Child Controls from a parent datalist or datagrid contro =?Utf-8?B?TW9vampvbw==?= Microsoft ASP .NET 0 8th Jul 2005 09:57 PM
Mdi Parent controls showing on Mdi Child forms =?Utf-8?B?QnJpbmRsZXk=?= Microsoft Dot NET 2 7th Jan 2005 05:33 AM
accessing parent menu from child form RT Microsoft VB .NET 0 23rd Sep 2003 02:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:07 PM.