[Resolve] "Object reference not set to an instance of an object."
Hello,
So I've started trying to use more control object arrays thanks to the help I received here earlier and I've managed to figure out how to handle some events e.g. keypress, but for some reason other events in the "System.EventArgs" set e.g. "Leave" and "TextChanged" result in the above error whenever they are called.
I assign the handle with "address of" when filling the array:
It would really help clean my code up a great deal if I could handle the "Leave" and "TextChanged" events through the arrays as the only way I can get it to work is to make separate functions for each of the ton of boxes I need. I also have to copy the reference through a separately named variables and then use those separately variable names to handle these events.
Any help would be much appreciated.
Thanks as always in advance.
Hello,
So I've started trying to use more control object arrays thanks to the help I received here earlier and I've managed to figure out how to handle some events e.g. keypress, but for some reason other events in the "System.EventArgs" set e.g. "Leave" and "TextChanged" result in the above error whenever they are called.
I assign the handle with "address of" when filling the array:
VB.NET:
This Results in an error:
private sub FillTextboxArray()
for row = 1 to 5 step 1
Dim box As New TextBox
AddHandler box.TextChanged, AddressOf ArrayHandler_TextChanged
Me.MyGroup.Controls.Add(box)
Me.MyArray(row) = box
next row
end sub
Private Sub ArrayHandler_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ArrayHandler.TextChanged
ArrayHandler.Text = "Hello"
End Sub
This does not:
private sub FillTextboxArray()
for row = 1 to 5 step 1
Dim box As New TextBox
AddHandler box.KeyPress, AddressOf ArrayHandler_KeyPress
Me.MyGroup.Controls.Add(box)
Me.MyArray(row) = box
next row
end sub
Private Sub ArrayHandler_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ArrayHandler.KeyPress
ArrayHandler.Text = "Hello"
End Sub
It would really help clean my code up a great deal if I could handle the "Leave" and "TextChanged" events through the arrays as the only way I can get it to work is to make separate functions for each of the ton of boxes I need. I also have to copy the reference through a separately named variables and then use those separately variable names to handle these events.
Any help would be much appreciated.
Thanks as always in advance.
Last edited: