VB.net, VS 2012
I've got a form (frmParts) that had too many controls on it. It was getting very hard to manage. I spent the last couple days breaking it up into several UserControls (each with 20 to 30 text boxes, labels, radio buttons, etc).
Rather than dragging a copy of each UserControl onto the form at design-time, I'm doing it in code when the parent form is loaded.
The UserControls are ucPartsHeader, ucPartsSH, ucPartsTCD, ucPartsCH, and ucPartsECD.
When ucPartsHeader is added to frmParts its Load event fires. But when the other 4 are added, their Load events do not fire. I've been over and over and over the code. I can't find what's wrong. I've done an override of the Load events and that doesn't work either. It just never gets there.
All the pre-Load event code seems to fire (like creating bar managers, table adapters, etc that are on each UserControl).
Each UserControl has a public function called pubfncLoadData.
What I have tried:
Here's my code that runs in the Load event of frmParts:
Dim sqlWhere As String = " WHERE PartID = " & Me.partID.ToString
Me.pvtfncLoadData(sqlWhere)
Dim ucPH As New ucPartsHeader
Me.pnlHeader.Controls.Add(ucPH)
ucPH.pubfncLoadData(sqlWhere)
Dim ucSH As New ucPartsSH
Me.pnlSH.Controls.Add(ucSH)
ucSH.pubfncLoadData(sqlWhere)
Dim ucTCD As New ucPartsTCD
Me.pnlTCD.Controls.Add(ucTCD)
ucTCD.pubfncLoadData(sqlWhere)
Dim ucCH As New ucPartsCH
Me.pnlCH.Controls.Add(ucCH)
ucCH.pubfncLoadData(sqlWhere)
Dim ucECD As New ucPartsECD
Me.pnlECD.Controls.Add(ucECD)
ucECD.pubfncLoadData(sqlWhere)
The Load event code for each of the 5 UserControls is nearly identical. But it just doesn't even get there for 4 of the UserControls.
I have Try/Catch blocks in all this so it posts the errors to a log file and keeps going. The form is created and the user controls show up. But the UserControls have no data in them because of the fact that each of their Load events don't run.
I know someone's going to want to see a lot more code here to be able to help. I'm just starting here for now to see if anyone has any insight on how I'm creating and adding the UserControls to the main form. Since they are all nearly the same, I don't understand why the first one works and the others do not. I commented out the first one to see if that would allow the 2nd one to work. That didn't do it. The 2nd, 3rd, 4th, and 5th don't work at all anyway, even with the first one commented out. This is my first time using UserControls to organize things a little better. Maybe I'm missing something obvious here.
Thanks,
A.