I fear that there is something obviously wrong with my code, but I have come across a situation where the Form.Load
event is not firing when I create and show my form.
The form is not subclassed (as I've seen some problems with that in some searches), and I am not getting any errors thrown when I step through the code in the debugger.
I have a break point set on the IDE-created form load function (which does have the Handles MyBase.Load
signature suffix) but the breakpoint is never reached and the form does display and work.
The form is passed three arguments in the constructor but the IntializeComponent()
function is called before anything else is done.
Code:
Public Sub New(ByVal argA As Object, ByVal argB As Object, ByVal mode As FormMode)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Other code here,
' No errors generated
'
End Sub
The form load function is as follows, (but this is never actually executed as the event is not fired).
Code:
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
End If
End Sub
I might add I am using some databinding with some controls and the argA
object, but if this was producing an error I thought I would have seen this (I have CLR Execpetions settings set to Thown in the debugger > exceptions window)
Any ideas why this might be occurring?
You can use the Form. Invalidate(); or Form. Refresh(); methods.
The Form Load Event in VB . NET. An important event you'll want to write code for is the Form Load event. You might want to, for example, set the Enabled property of a control to False when a form loads. Or maybe blank out an item on your menu.
An event is an action that you can respond to, or "handle," in code. Events can be generated by a user action, such as clicking the mouse or pressing a key, by program code, or by the system.
I just had a similar issue (it was in Shown
event, not Load
, but the root cause is the same). The reason was hidden deep in one of the ancestors - there was an unhandled NullReferenceException
thrown and this exception was somehow "muted".
I found it after extensive debugging with F11.
But... when writing this answer I found this post on SO
Just add Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
in your Main()
method.
If you're using a 64-bit machine, it provides you with the solution (it worked in my case, too).
I had a similar problem. On opening the form for the first time, the load event would not be tiggered but on opening it the second time, all would be well. The problem tuned out to be one of my text boxes which was bound to a field that I had deleted from the database (sql server - I was using datasets, tableadaptors and bindingsources in a fairly standard way).
Make sure that all the controls on your form that are databound have fields that exist in the dataset and that the dataset is an accurate reflection of the underlying database table (the easiest was to do this last bit is to use the "Configure data source with wizzard" button on the data sources window (menu -data - show data sources) and remove the table. Then use it again to add the table back- this should make sure all the data matches.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With