Hi,
I have a Form which has the property IsMdiContainer = True. So it contains a
whole bunch of MdiChilds. Those MdiChilds are all instances of two forms I
have: I have some that are an instance of frmSource, and some that are
instances of frmTarget.
I now have a button on my MdiParent that, if clicked on, have to refresh all
the instances of frmSource. So I putted the following code underneath it:
Dim FormSource as frmSource
For Each FormSource In Me.MdiChildren
FormSource.FillGrid_TS()
Next
This works fine when I have ONLY instances of frmSource, but it doesn't work
when I have also instances of frmTarget.
I found alreadyy a solution ofr my problem, but I still think it's a little
bit weird. (see underneath this). Does anydbody know a better/ more corect
solution?
Dim FormSource As frmSource
Dim FormTest As Form
btnRefreshAll.Enabled = False
For Each FormTest In Me.MdiChildren
If FormTest.Name = "frmSource" Then
FormSource = FormTest
FormSource.FillGrid_TS()
End If
Next
Thanks a lot in advance!
Pieter 4 7019
* "DraguVaso" <pi**********@hotmail.com> scripsit: I found alreadyy a solution ofr my problem, but I still think it's a little bit weird. (see underneath this). Does anydbody know a better/ more corect solution?
Dim FormSource As frmSource Dim FormTest As Form btnRefreshAll.Enabled = False For Each FormTest In Me.MdiChildren If FormTest.Name = "frmSource" Then
I would prefer 'If TypeOf FormTest Is frmSource Then'.
FormSource = FormTest FormSource.FillGrid_TS() End If Next
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
"DraguVaso" <pi**********@hotmail.com> schrieb Dim FormSource As frmSource Dim FormTest As Form btnRefreshAll.Enabled = False For Each FormTest In Me.MdiChildren If FormTest.Name = "frmSource" Then FormSource = FormTest FormSource.FillGrid_TS() End If Next
Option Strict On
'...
Dim FormSource As frmSource
Dim FormTest As Form
btnRefreshAll.Enabled = False
For Each FormTest In Me.MdiChildren
If TypeOf FormTest Is frmSource Then
FormSource = Directcast(FormTest, frmSource)
FormSource.FillGrid_TS()
End If
Next
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
The issue here is that you did not check to see what type of form you have
inside your loop. The MdiChildren collection contains ALL MdiChildren, so
your loop enumerator must be of type Form and then inside the loop, check to
see what specific type of form you have:
Dim countSource As Integer
Dim countTarget As Integer
Dim child As Form
For Each child In MdiChildren
If TypeOf child Is Source Then
countSource += 1
ElseIf TypeOf child Is Target Then
countTarget += 1
End If
Next
MessageBox.Show(countSource.ToString() & " Source Forms" & _
ControlChars.CrLf & _
countTarget.ToString() & " Target Forms")
However, I think that a better design will be more successful. Consider
making your own collections for the different types of forms. In your
MdiParent form, do something like this:
Private Sources As New Collection
Private Targets As New Collection
Private Function getNewSource() As Source
Dim f As New Source()
f.MdiParent = Me
Sources.Add(f)
Return f
End Function
Private Function getNewTarget() As Target
Dim f As New Target()
f.MdiParent = Me
Targets.Add(f)
Return f
End Function
Then you could use code like this to walk over whichever collection you
choose:
Dim f As Form
For Each f In Sources
'Do something to each Source form
Next
If your application creates these two types of forms from say, two different
menu items or whatever (two different event procedures), you could even
refactor the two event procedures into one method of your MdiParent form
that handles both events and decides based on the identity of "sender" which
form to create. This is an example of the "Factory Method Design Pattern"
--
Peace & happy computing,
Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
Thanks a lot for the input guys!
Pieter
"Mike Labosh" <ml*****************@vbsensei.com> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl... The issue here is that you did not check to see what type of form you have inside your loop. The MdiChildren collection contains ALL MdiChildren, so your loop enumerator must be of type Form and then inside the loop, check
to see what specific type of form you have:
Dim countSource As Integer Dim countTarget As Integer Dim child As Form
For Each child In MdiChildren
If TypeOf child Is Source Then countSource += 1 ElseIf TypeOf child Is Target Then countTarget += 1 End If
Next
MessageBox.Show(countSource.ToString() & " Source Forms" & _ ControlChars.CrLf & _ countTarget.ToString() & " Target Forms")
However, I think that a better design will be more successful. Consider making your own collections for the different types of forms. In your MdiParent form, do something like this:
Private Sources As New Collection Private Targets As New Collection
Private Function getNewSource() As Source Dim f As New Source() f.MdiParent = Me Sources.Add(f) Return f End Function
Private Function getNewTarget() As Target Dim f As New Target() f.MdiParent = Me Targets.Add(f) Return f End Function
Then you could use code like this to walk over whichever collection you choose:
Dim f As Form
For Each f In Sources 'Do something to each Source form Next
If your application creates these two types of forms from say, two
different menu items or whatever (two different event procedures), you could even refactor the two event procedures into one method of your MdiParent form that handles both events and decides based on the identity of "sender"
which form to create. This is an example of the "Factory Method Design Pattern" -- Peace & happy computing,
Mike Labosh, MCSD MCT Owner, vbSensei.Com "Escriba coda ergo sum." -- vbSensei
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Supra |
last post by:
i got mdichild working. i'm working on similar to mirc chat. when i
joined channel #vb the first mdichild is on. then when i wanted to join
another channel #visualbasic. then i got second mdichild...
|
by: Adi |
last post by:
Hi
I got problem with Mdi form, I would like to check if child form is already
created and opened
(I have a few child forms).
And if it is open to make it focus else create new instance of the...
|
by: Vlado J. \(www.excelleinc.com\) |
last post by:
Hi,
I have a MDI parent form that opens form as MDIChildren.
I'm trying to check if form is already opened and if it is to give it focus.
I keep getting error messages and no matter what I try...
|
by: LCAdeveloper |
last post by:
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...
|
by: MuZZy |
last post by:
Hi,
I wounder if someone could help me here: app has an MdiParent form - i
need to get some notification in form of an event when any MdiChild
forms are added to/removed from...
|
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...
|
by: iDesmet |
last post by:
Hallo,
First of all, I'm new at this group and I'm currently learning VB.NET
by my own (later I want to learn C#, but that's another story). In
other words, I'm a Newbie.
Anyway, I was...
|
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...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |