[ACCEPTED]-Form.Load event not firing, form showing-event-handling

Accepted answer
Score: 28

I just had a similar issue (it was in Shown event, not 9 Load, but the root cause is the same). The reason 8 was hidden deep in one of the ancestors 7 - there was an unhandled NullReferenceException thrown and this 6 exception was somehow "muted".

I 5 found it after extensive debugging with 4 F11.

But... when writing this answer I found 3 this post on SO

Just add Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException) in your Main() method.

If you're 2 using a 64-bit machine, it provides you 1 with the solution (it worked in my case, too).

Score: 7

I had a similar problem. On opening the 19 form for the first time, the load event 18 would not be tiggered but on opening it 17 the second time, all would be well. The 16 problem tuned out to be one of my text boxes 15 which was bound to a field that I had deleted 14 from the database (sql server - I was using 13 datasets, tableadaptors and bindingsources 12 in a fairly standard way).

Make sure that 11 all the controls on your form that are databound 10 have fields that exist in the dataset and 9 that the dataset is an accurate reflection 8 of the underlying database table (the easiest 7 was to do this last bit is to use the "Configure 6 data source with wizzard" button on the 5 data sources window (menu -data - show data 4 sources) and remove the table. Then use 3 it again to add the table back- this should 2 make sure all the data matches.

Hope this 1 helps.

Score: 4

OK I had the SAME problem (I think) and 5 the clues here helped. It was databinding 4 (sort of)

I had properties of some controls 3 bound to settings and when I delete these 2 settings the form load event stopped running. Removed 1 the bindings and now it is running again.

Score: 2

Here is another idea.

What happens if you 4 set all exception types (not just for the 3 CLR) to be thrown instead of user-unhandled. Does 2 the application break anywhere at all?

Also, just 1 to double check, you are in debug mode right?

Score: 1

The problem you are experiencing may be 10 caused by the application needing to fully 9 load the form before you can do the "other 8 code." This could be due to the other code 7 dealing with objects on the form that haven't 6 finished loading. You could use a timer 5 that gets enabled in the load function to 4 execute the other code. This way you don't 3 have any timing issues and you can first 2 load the form, and then a split second later, run 1 the code you want from the timer.

Score: 1

Is your windows form inheriting from a base 8 page? If so, the base page probably also 7 has a Form Load event handler. In that 6 base page Form Load event handler you will 5 probably find an exception that is being 4 thrown. So it is exiting the base page 3 form load event handler and not firing the 2 form load event handler in your inherited 1 windows form.

Score: 1

I had a similar issue, the problem was a 4 mistake in the databinding. Omit the code 3 for databinding and give it a try. I think 2 the load event handler will be hit. Then 1 see what's wrong with the databinding part.

Score: 1

Had the same problem. Checked my data bindings, everything 6 looked ok. Got to thinking, even though 5 form was closed, maybe .NET wasn't sure 4 (old days, sometimes forms were only hidden 3 and not really closed).

I added the event 2 handler FormClosed and put a single line 1 in it:

Private Sub frmScheduleInquiry_FormClosed(sender As Object, e As   System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
End Sub

Problem solved!

Score: 1


Have spent 4 hours and finally 12 got clues from this answers. in my case 11 i was having couple of TextBox control on 10 the form bound to a BindingSource with respective 9 column, i still have that bindingsource 8 on the form but what was happened that i 7 deleted one column from underlying database 6 table so on the form there is still one 5 TextBox exist pointing to that column with 4 bindingsource, in fact there is no column 3 like that because i deleted !..... this 2 lead Form.load event was not firing ........finally 1 fixed..

thanks to all of you ..

Score: 1

I had the exact same problem just happen 8 to me. Turns out I had added some ApplicationsSettings 7 properties to a form TextBox control, but 6 later wanted to delete them. I thought I had cleared 5 everything out, but obviously I didn't - and 4 this was what caused the Form_Load() (and 3 maybe other events as well) to not fire. Deleting 2 and then re-adding the offending TextBox 1 did the trick.

Hope this helps

Score: 0

Matt is probably right about this one. Have 7 you tried adjusting your code like this:

Private Sub frmInstrumentEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not argA Is Nothing Then ' argA set in constructor
      ' Operations using argA
      MessageBox.Show("argA has not been set")
End If
End Sub

If 6 the messagebox appears it means that the 5 event is fired before your argument is initialized. It 4 would also account for the 'strange' behaviour 3 concerning closing/opening the form.

Have 2 you tried running the argA operations in 1 the 'Shown' event?

Score: 0

Not sure if this will help, but I just ran 3 into this issue because somebody mistakenly 2 deleted the Handles Me.Load. I see you show 1 MyBase.Load try changing it to Me.Load.

Score: 0

I had a similar issue. It turned out that 5 I was not using the Show method on the form 4 - instead using a user32.dll ShowWindow 3 call. This means the form still appeared, but 2 the Load event was never fired because the 1 dotNet Show method was never called.

Score: 0

I know that this is an old post, but I thought 14 that if someone was searching this issue, that 13 my fix to this problem might help.

I was 12 having this same problem as stated in the 11 originally posted question, but I didn't 10 have any data bound fields on the form. I 9 found that the problem was in the fact that 8 I was using the CurrentDeployment.CurrentVersion method and it was causing 7 the silent problem. I set the application 6 from debug mode to release and the problem 5 still existed. Through trial and error I 4 remarked out the defining method Dim xVersion As Version = ApplicationDeployment.CurrentDeployment.CurrentVersion and presto... its 3 now working as usual.

I ended up changing 2 the orginal code the code below.

    Dim xVersion As Version = ApplicationDeployment.CurrentDeployment.CurrentVersion
    sysVersion = String.Format("{0}.{1}{2}.{3}", xVersion.Major, xVersion.Minor, xVersion.Build, xVersion.Revision)

New code

#If (DEBUG) Then
    sysVersion = "[Debug mode]"
    Dim xVersion As Version = ApplicationDeployment.CurrentDeployment.CurrentVersion
    sysVersion = String.Format("{0}.{1}{2}.{3}", xVersion.Major, xVersion.Minor, xVersion.Build, xVersion.Revision)
#End If

I 1 hope this helps someone. Happy Coding...

Score: 0

Same problem, I rewrote the designer and 3 that fixed it. The designer was loading 2 then crashing (silently of course), and 1 form_load was not firing due to that.

Score: 0

Had same issue, but cause was totally different. Form 2 was being shown using form.Show() instead 1 of form.ShowDialog()

Score: 0

I experienced this symptom when building 8 and running a .NET 4.0 WinForms application 7 which loaded a series of older assemblies 6 (.NET 2.0; .NET 1.1).

In the past I had seen 5 this cause a mixed-mode assembly exception. In 4 this particular case, the main Form loaded 3 without exception and without executing 2 any of its Form Load code.

The solution, in 1 my case, was to set useLegacyV2RuntimeActivationPolicy="true" in the App.config document.

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
Score: 0

Make sure your "Solution Configuration" box 3 at the top of your IDE is showing "Debug". I 2 found that if it showed "Release" the "Load" method 1 was not captured by the debugger.

Score: 0

In my case, the main form had WindowState: Maximized set in the 3 designer. This was causing the window to 2 be drawn on screen prior to the Load event 1 firing.

More Related questions