Link to home
Start Free TrialLog in
Avatar of DjJohnny
DjJohnny

asked on

AddHandler "Is not an event of object"

Hi Experts.
I have a form that opens as a control of a panel.
    Private Sub OpenfrmTakeOffSubWalls(ByVal Edited As Boolean)
        Dim SubFrm = New frmTakeOffSubWalls
        With SubFrm
            .TopLevel = False
            .Dock = DockStyle.Fill
            .Anchor = AnchorStyles.Bottom
            .WindowState = FormWindowState.Maximized
            Me.Panel1.Controls.Add(SubFrm)
            AddHandler SubFrm.UpdateTakeOffGrid, AddressOf FillTakeOffGrid

            .Show()
        End With
    End Sub

works well. When I move the  " Dim SubFrm = New frmTakeOffSubWalls" to the top of the form:

Public Class frmTakeOff
     Dim SubFrm = New frmTakeOffSubWalls

I then get an error frmTakeOffSubWalls is not an event of "object"

The reason I moved the declaration to the top is I need to refer to the form later on a click event of the subform.

Thank you
John

Avatar of VBRocks
VBRocks
Flag of United States of America image

Can you post the event declaration for "UpdateTakeOffGrid"?

Also post the declaration for "FillTakeOffGrid".

Thanks.
Avatar of DjJohnny
DjJohnny

ASKER

Thank you VBRocks,

Public Class frmTakeOffSubWalls
    Dim CurrentTakeOffId As Integer
    Dim CurrentRevisionId As Integer
    Public CurrentTakeOffItemId As Integer
    Dim FormHasChanged As Boolean
    Public EditMode As Boolean
    Public Event UpdateTakeOffGrid()

and


    Private Sub FillTakeOffGrid()
        Try
            Me.TakeOffItemsTableAdapter.Fill(Me.DsTakeOff.TakeOffItems, CurrentTakeOffId, CurrentRevisionNumber)
            Me.TakeOffItemsMaterialTableAdapter.Fill(Me.DsTakeOff.TakeOffItemsMaterial, CurrentTakeOffId)
            ExpandTakeOffGrid()
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

Well, 2 things you can try:

First, declare FillTakeOffGrid as Public.

Second, Change your event declaration as follows:

    Public Event UpdateTakeOffGrid(ByVal sender As Object, ByVal e As EventArgs)


    Then, update the FillTakeOffGrid method signature to match the event declaration:

        Public Sub FillTakeOffGrid(ByVal sender As Object, ByVal e As EventArgs)


Try those and see if that works for you.

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, duh...  Good catch Idle_Mind.