473,687 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MDIChild form controls: how to pass information between them?

Can anyone help me with this? I'm trying to get an MDIChild form to lookup
the value of a control on another open MDIChild form, but can't seem to get
the right syntax.

Let's say the two child forms are Form1 and Form2. In VB4 I could use (in
Form2):
\\
If Form1.Option1.V alue = True Then
//

However, in vb.NET 2003, even if I put the following in the Form2's Load event
\\
Dim MDIa as Form1
.....
If MDIa.Radiobutto n1.Checked=True Then
//
I get the usual 'An unhandled exception of type
'System.NullRef erenceException ' message .... 'Object reference not set to an
instance of of an object'

even though when I put the cursor over the code 'MDIa.' a pop-up message
says 'Dim MDIa as ParentFileName. Form1' (the same pop-up says 'MDIa =
Nothing' if you Break aftyer the above runtime error occurs).

I have tried using 'Dim MDIa as New Form1' instead, which doesn't produce
the error but becasue I have declared it as 'New Form1' the default
Radionbutton on the form is checked instead of the one that I know is checked
on the (hidden) form (at least that is what I think is happening).

How can I get MDIChild Form2 to tell me the current status of a control on
MDIChild Form1. I have even tried going via the Parent form using some code
that (O)enone kindly gave me a couple of weeks ago, but I don't yet have
sufficient ability in vb.NET 2003 to correctly setup the syntax.

Many thanks in advance for any help that anyone can give me.

Nov 21 '05 #1
1 4887
Thanks very much for your reply, I'll give what you suggest a whirl. :-)

"Oenone" wrote:
LCAdeveloper wrote:
[...]
How can I get MDIChild Form2 to tell me the current status of a
control on MDIChild Form1.


You need to get a reference to the actual instance of Form1. Declaring a
Form1 object simply gets you a pointer or a brand new form, not the existing
instance.

To get the instance, first use the MdiParent property of Form2. This will
return you the MDI parent form that contains Form1 and Form2.

From here, you can access the MDI form's MDIChildren array, which contains
all of the child forms that are currently open within the MDI parent. One of
them will be your Form1 form, and from there you can read the control
properties you are after.

I personally use the following function which I have added to my MDI form:
\\\
'
' Scans all the MDI Child forms looking for one of the specified type.
' If one is found, it will be returned, otherwise Nothing is returned.
'
Public Function FindChildForm(B yVal SearchFormType As Type, Optional
ByVal FormCaption As String = "*") As Form

Dim f As Form

For Each f In Me.MdiChildren
If TypeName(f) = SearchFormType. Name And f.Text Like FormCaption
Then
f.Activate()
Return f
End If
Next

Return Nothing

End Function
///

This allows you to pass a Form type and optionally a caption (which allows
you to distinguish between multiple instances of the same form).

To use it, from Form2, try this code:

\\\
Dim myMDI as MyMDIForm 'change to whatever class your MDI uses
Dim myForm1 as Form1

'Get a reference to the MDI parent form
myMDI = DirectCast(Me.M diParent, MyMDIForm)

'Get a reference to the Form1 form
myForm1 = DirectCast(myMD I.FindChildForm (GetType(Form1) ), Form1)

If myForm1 Is Nothing Then
MsgBox("Couldn' t find Form1")
Else
MsgBox(myForm1. RadioButton1.Ch ecked)
Endif
///

(That code typed straight into this message and so not tested, but it should
be close enough :-)

--

(O)enone

Nov 21 '05 #2

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

Similar topics

16
7222
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
6
6220
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 method from the mdichild, I get this error: C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The name 'test' does not exist in the class or namespace 'Tournament.frmLogin' frmLogin is the mdichild.
2
7372
by: SpotNet | last post by:
Hello NewsGroup, I have a MDIParent form with a docked left treeview control, a splitter control and a generic docked control on the right. Kind of looks like Windows Explorer, though it's functionality is quite different. I have a function where an MDIChild is activated, well attempted to do so. When I call the MDIChild form, I get the form caption (on the MDIParent) of the MDIChild and its' control menus but the client area still has...
19
1963
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works" End Sub End Class
2
1864
by: Thorgal | last post by:
Hello all I have 2 questions First: I'm trying to print a Listview from an mdichild but how can i address this listview. For example, FrmMain is my Main form. In this Main form I have several mdichildren.
1
1581
by: ian807 | last post by:
I have a legacy vb.net mdi word processor application which I'm modifying. I've created many new dialogs. In vb6, I could reference controls on the child form with code like this: Dim text as string temp = frmMDIParent.ActiveForm.TXTextControl1.text in vb6, this worked from any button on any dialog in the project. In
8
36126
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query button on it. If the query returns multiple results, a new window is opened with a grid containing the results. When the user double clicks on the desired row in the grid, I want the first form to populate with the correct data. I don't know how...
0
1119
by: Amritha.Datta | last post by:
I want to update MDIChild grid control by setting a datasource. How does it possible from parent form? In other words, I have a data grid control on a MDIChild form. I am binding the data source from datagrid at the time of loading the MDI Child. Now, I need to refresh the data grid when there is a button click happens on the parent form. I do not want to load the complete MDI child again. I just want to update or refresh the data...
0
898
by: Amritha.Datta | last post by:
I want to update MDIChild grid control by setting a datasource. How does it possible from parent form? In other words, I have a data grid control on a MDIChild form. I am binding the data source from datagrid at the time of loading the MDI Child. Now, I need to refresh the data grid when there is a button click happens on the parent form. I do not want to load the complete MDI child again. I just want to update or refresh the data...
0
8590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8781
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8783
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7618
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4542
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2214
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1947
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.