Solved

ACCESS MDICHILD VARIABLES OR PROPERTIES

Posted on 2012-12-30
23
266 Views
Last Modified: 2012-12-31
Hi All,

I create a mdi parent and several mdi child forms.
I want to access mdi child form variables and properties.

Public Class Form3
    Implements MdiChildForm

    Private clsFormAuthority As clsFormAuthority

    Public Sub New(ByVal clsFormAuthority As clsFormAuthority)

        Me.InitializeComponent()

        Me.clsFormAuthority = clsFormAuthority

    End Sub

    Private intMode As Int16 = ERV_GLOBAL.MB_VIEW

    Public Property Mode() As Integer
        Get
            Return intMode
        End Get
        Set(ByVal value As Integer)
            intMode = value
        End Set
    End Property

End Sub

How could I access :

1. clsFormAuthority
2. Mode Properties

Thank you.
0
Comment
Question by:emi_sastra
  • 14
  • 6
  • 2
  • +1
23 Comments
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 38730592
Make both of clsFormAuthority and Mode public.
and the cast your reference to form like ActiveChild in Form3 and then you can access the required data member directly.
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 38730594
You can also do this ass following
Dim child As Form3= Me.ActiveMDIChild

child.clsFormAuthority = *****
child.Mode  = *****

for more reference please follow the urls:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activemdichild.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
http://p2p.wrox.com/vb-net-2002-2003-basics/56165-controlling-mdi-child-form-mdi-parent-panel.html
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38730838
Please my code.

  If ERV_GLOBAL.Form_Active("Form3", Me) Then
            Dim frm As Form = Me.ActiveMdiChild

           
            Me.ShowHideControl(intMode, clsFormAuthority)
        Else
            If clsFormAuthority.blnAccess Then
                Dim Form3 As New Form3(clsFormAuthority)
                Form3.MdiParent = Me
                Form3.Show()
            End If
        End If

What should I do ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38730925
Change this line

Dim frm As Form = Me.ActiveMdiChild

to

Dim frm As Form3 = Me.ActiveMdiChild

I suppose this

Me.ShowHideControl(intMode, clsFormAuthority)

would be

Me.ShowHideControl(frm.intMode, frm.clsFormAuthority)
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731554
Hi CodeCruiser,

I've got compile error :

Error      1      'WindowsApplication1.Form3.intMode' is not accessible in this context because it is 'Private'.       
Error      2      'WindowsApplication1.Form3.clsFormAuthority' is not accessible in this context because it is 'Private'.       

Thank you.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38731561
Use "Mode" instead of "intMode".

For "clsFormAuthority", you'd need to change the access modifier to public.  *This has already been mentioned!*

Change:

    Private clsFormAuthority As clsFormAuthority

To:

    Public clsFormAuthority As clsFormAuthority
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731587
Could access to its property ?

 Public Property Mode() As Integer
        Get
            Return intMode
        End Get
        Set(ByVal value As Integer)
            intMode = value
        End Set
    End Property

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731597
- Use "Mode" instead of "intMode".
Get it.

One more problem.

 Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim frm As Form = Me.ActiveMdiChild
        If Not IsNothing(frm) AndAlso TypeOf frm Is MdiChildForm Then
            DirectCast(frm, MdiChildForm).Add()
        End If
    End Sub

How could I change mode of active mdi child form ?
Remember there are several forms.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731603
I use :

Public Interface MdiChildForm
    Sub Add()
    Sub Update()
    Sub Delete()
    Sub Save()
    Sub Print()
    Sub Cancel()
End Interface

at mdi form.

Thank you.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38731650
You'd have to add Mode() to your Interface!
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731715
- You'd have to add Mode() to your Interface!
I don't get it.

 Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Me.intMode = ERV_GLOBAL.MB_ADD

        Dim frm As Form = Me.ActiveMdiChild
        If Not IsNothing(frm) AndAlso TypeOf frm Is MdiChildForm Then
            DirectCast(frm, MdiChildForm).Add()
         
mdichild.mode = me.intMode --> How to do this ?
        End If

      End Sub

How could I do it ?

Thank you.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:emi_sastra
ID: 38731717
Sorry,

  Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Me.intMode = ERV_GLOBAL.MB_ADD

        Dim frm As Form = Me.ActiveMdiChild
        If Not IsNothing(frm) AndAlso TypeOf frm Is MdiChildForm Then
            DirectCast(frm, MdiChildForm).Add()

--problem below code
            Me.ShowHideControl(intMode, frm.clsFormAuthority)
        End If
 
    End Sub


Thank you.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 38731796
So you'd add a "Mode" Property to your Interface:

    Public Interface MdiChildForm
        Sub Add()
        Sub Update()
        Sub Delete()
        Sub Save()
        Sub Print()
        Sub Cancel()

   Property Mode As Integer
    End Interface

Then, in your Form, make the Mode() Property Implement the Interface Property:

    Public Class Form3
        Implements MdiChildForm

        Private intMode As Int16 = ERV_GLOBAL.MB_VIEW

        Public Property Mode() As Integer Implements MdiChildForm.Mode
            Get
                Return intMode
            End Get
            Set(ByVal value As Integer)
                intMode = value
            End Set
        End Property

    End Class

Now you can cast "frm" like you did before to set Mode():

    DirectCast(frm, MdiChildForm).Add()  
    DirectCast(frm, MdiChildForm).Mode = Me.intMode
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731880
Sorry Mode has no problem anymore since I have code at form3 below :

 Public Class Form3
       Implements MdiChildForm

    Public clsFormAuthority As clsFormAuthority
    Private intMode As Int16 = ERV_GLOBAL.MB_VIEW

    Public Sub New(ByVal clsFormAuthority As clsFormAuthority)

        Me.InitializeComponent()

        Me.clsFormAuthority = clsFormAuthority

    End Sub

    Public Property Mode() As Integer
        Get
            Return intMode
        End Get
        Set(ByVal value As Integer)
            intMode = value
        End Set
    End Property

  Public Sub Add() Implements MdiChildForm.Add
        Me.Mode = ERV_GLOBAL.MB_ADD
        MsgBox(Me.Name & " CREATE")
    End Sub

End Sub

The problem is to access clsFormAuthority at mdi parent.

 Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Me.intMode = ERV_GLOBAL.MB_ADD

        Dim frm As Form = Me.ActiveMdiChild
        If Not IsNothing(frm) AndAlso TypeOf frm Is MdiChildForm Then
            DirectCast(frm, MdiChildForm).Add()
            'Me.ShowHideControl(intMode, frm.clsFormAuthority)
        End If
 
    End Sub

frm.clsFormAuthority is the problem now.

Thank you.
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 500 total points
ID: 38731898
Right..."frm" is a generic Form, which has no knowledge of "clsFormAuthority".  Your MdiChildForm Interface also will not be able to access it.

So either you need to:
(1) Cast "frm" to a Type that does have knowledge of "clsFormAuthority".
(2) Add "clsFormAuthority" as a Property of MdiChildForm Intefrace (just like Mode).
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731907
Ok. Let me try it.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731911
-(1) Cast "frm" to a Type that does have knowledge of "clsFormAuthority".
Have no idea about it.

- (2) Add "clsFormAuthority" as a Property of MdiChildForm Intefrace (just like Mode).
Let me try first.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731919
Public Interface MdiChildForm
    Sub Add()
    Sub Update()
    Sub Delete()
    Sub Save()
    Sub Print()
    Sub Cancel()
    Sub FormAuthority()
End Interface

  Public Property FormAuthority() Implements MdiChildForm.FormAuthority
        Get
            Return clsFormAuthority
        End Get
        Set(ByVal value As Object)
            clsFormAuthority = value
        End Set
    End Property

Error      1      Class 'Form3' must implement 'Sub FormAuthority()' for interface 'MdiChildForm'.       

Error      2      'FormAuthority' cannot implement 'FormAuthority' because there is no matching property on interface 'MdiChildForm'.       

Thank you.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38732075
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38732097
Public Interface MdiChildForm
    Sub Add()
    Sub Update()
    Sub Delete()
    Sub Save()
    Sub Print()
    Sub Cancel()
    Property FormAuthority()
End Interface

 Public Property FormAuthority() As Object Implements MdiChildForm.FormAuthority
        Get
            Return clsFormAuthority
        End Get
        Set(ByVal value As Object)
            clsFormAuthority = value
        End Set
    End Property

Then what should I do at main form ?

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38732099
I try this.

 Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Me.intMode = ERV_GLOBAL.MB_ADD

        Dim frm As Form = Me.ActiveMdiChild
        If Not IsNothing(frm) AndAlso TypeOf frm Is MdiChildForm Then
            DirectCast(frm, MdiChildForm).Add()
            clsFormAuthority = DirectCast(frm, MdiChildForm).FormAuthority
            Me.ShowHideControl(intMode, clsFormAuthority)
        End If
 
    End Sub

Thank you.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38732604
...and does that work now?

Instead of using DirectCast() each time, you can create a local variable to use:
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Me.intMode = ERV_GLOBAL.MB_ADD

        Dim frm As Form = Me.ActiveMdiChild
        If Not IsNothing(frm) AndAlso TypeOf frm Is MdiChildForm Then
            Dim child As MdiChildForm = DirectCast(frm, MdiChildForm)
            ' ... now use "child" ...
            child.Add()
            Me.ShowHideControl(intMode, child.FormAuthority)
        End If
 
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 38733852
Hi All,

Thank to all of you very much for your help.

Thanks to Idle Mind that helps a lot.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now