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

Visual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

Can you post the event declaration for "UpdateTakeOffGrid"?

Also post the declaration for "FillTakeOffGrid".


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.

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Oh, duh...  Good catch Idle_Mind.