Link to home
Start Free TrialLog in
Avatar of 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
            AddHandler SubFrm.UpdateTakeOffGrid, AddressOf FillTakeOffGrid

        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

Avatar of VBRocks
Flag of United States of America image

Can you post the event declaration for "UpdateTakeOffGrid"?

Also post the declaration for "FillTakeOffGrid".

Avatar of DjJohnny


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()


    Private Sub FillTakeOffGrid()
            Me.TakeOffItemsTableAdapter.Fill(Me.DsTakeOff.TakeOffItems, CurrentTakeOffId, CurrentRevisionNumber)
            Me.TakeOffItemsMaterialTableAdapter.Fill(Me.DsTakeOff.TakeOffItemsMaterial, CurrentTakeOffId)
        Catch ex As System.Exception
        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.

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
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.