Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,

I am new to vb.net.I have three form.
The first one is MDIparent form (Mainform) which will created unlimited MDIchild form of (Mpfform).Mpfform contain Data Grid View.
Each Mpfform can create only one (Dmfform -non MDI).
Dmfform contain one "Start" button.
 
My problem is, how can i address the specific Mpfform created by Mainform or
Dmfform created from specific Mpfform?
 
Ive tried using my code below with no success. Please help me.
 
1) code in Mainform : to create Mpfform
 
 
Public mpf(50) As Mpfform()
Public num As Integer = 0
 
Private Sub NewMenuItem_File_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewMenuItem_File.Click
 
        num += 1
        mpf(num) = New Mpfform()
 
'creating Mpfform

        mpf(num).Text = "ModbusPoll:" & CStr(num)
        mpf(num).Name = "ModbusPollFormFull" & num
 
'creating Dmfform
        mpf(num).dmf.Text = "Display Mode:" & CStr(num)
        mpf(num).dmf.Name = "Display Mode:" & num
 
'showing only Mpfform
        mpf(num).TopLevel = False
        mpf(num).BringToFront()
        mpf(num).Show()
  
 
End Sub
 

 
2) code in Mpfform - Showing Dmfform
 
 
Public dmf As New Dmfform
 
Private Sub DataDisplayModeMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataDisplayModeMenuItem.Click
 
        dmf.Show()
        
End Sub
 
 
3)code in Dmfform - addressing problem
 
 
Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
        
        If Mainform.mpf(Mainform.num).Datagridview.RowCount <> Nothing Then
        
            Me.mytimer3.Interval = 1000
            Me.mytimer3.Start()
        Else
            MsgBox("Definition of the modbus properties is currently not available." & vbNewLine & "Please define the properties in the Measurement window : Communication >> Modbus Properties")
 
        End If
       
End Sub
 
How can i address the correct DGV of Mpfform to this code?
 
"Mainform.mpf(Mainform.num).Datagridview.RowCount" ?
Posted 22-Jan-13 3:43am
juita134
Edited 24-Jan-13 0:28am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First off, you shouldn't be addressing the DGV at all - it locks the two separate objects "mpfform" and "dmfform" together, so you can't change how they work without considering the effects on the other. You should be working via properties which mask the inner workings.
 
I would do things a little differently: I would create an Event in the dmfform which the mpfform instance that creates it handles. When teh event was signalled by the dmfform, the event handler would set a property in the dmfform instance (it doesn't even need to save the instance(s) since it can use the sender Event parameter to identify the exact instance that is asking for the data.
 
The other solution is simpler, but nastier. Every Control (and Form is a Control) has a Tag property - when you create an instance of a dmfform you can set it's Tag to the mpfform that created it. The dmfform can then read the Tag, cast it to an mpfform instance and use a property to read the DGV count. It's nasty, because it requires that each dmfform is created by a mpfform (or by a class derived from mpfform) and can't be easily reused somewhere else.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].
 
I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid