Datagrid refresh problem... well... kinda...

Hello,

I am receiving an error telling me that i cannot open an already disposed form.

The strange thing is that the form (which is said to be disposed) is open.

The steps which lead to this error are:


1) Open Main Form
2) Open Form1
3) Close Form1
4) Open Form1
5) Open Form2 from Form1
6) Raise an event in Form1 from Form2

If I edit out the line which raises the event in Form1 - I do not get the error.

So what am I doing wrong with regards to raising the event???


Step 6) The code to raise event is:

Mod_Form1.RaiseEditRecordInserted()


Form1's Module code contains:

Public Event EditRecordInserted()
    Public Sub RaiseEditRecordInserted()
        RaiseEvent EditRecordInserted()
End Sub

Form1's load event has:

AddHandler Mod_Edit.EditRecordInserted, AddressOf HandleRecordInserted

And then there's the actual sub which is:

Public Sub HandleRecordInserted()
        fetchGridData(0)
End Sub


Any help appreciated - thanks.

KS
LVL 11
Ramesh SrinivasTechnical ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

angelfeijooCommented:
It might be that your line:

AddHandler Mod_Edit.EditRecordInserted, AddressOf HandleRecordInserted

Is referring to the first instance of Form1 which you closed before opening the new instance.

Make that line execute every time you re-open the Form1.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ramesh SrinivasTechnical ConsultantAuthor Commented:
It should execute every time the form1 opens because it is in the form_load event.
angelfeijooCommented:
Where do you assign value to Mod_Form1 ?
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Seems that you were right I guess.

What I did was to put a RemoveHandler into the form1_Closing event.

Looks like its working now.

cheers,

KS
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.