Problem in adding user control to a panel dynamically

a_shyam41

New member
Joined
Nov 20, 2005
Messages
1
Programming Experience
3-5
I have a windows form which has 3 user controls in it. Each user control has about 20 fields and I have replicated them as required. Each set is in a panel and when I try to add a blank user control to the same panel (on click of a button), it is not happening. This is the code I am using:

Dim assembly1 As System.Reflection.Assembly = [Assembly].LoadFrom("UserControls.dll")
Dim t As Type = assembly1.GetType("UserControls.UserMCDes")
Dim userMCDes As UserControls.UserMCDes = CType(Activator.CreateInstance(t), Control)
userMCDes.BackColor = System.Drawing.Color.WhiteSmoke
userMCDes.CreatedDate =
Nothing
userMCDes.CSRClosed = False
userMCDes.labelPostmark = "PostMark Date"
userMCDes.Location =
New System.Drawing.Point(6, 471)
userMCDes.Name = "UserMCDes" & index
userMCDes.rad2003 =
False
userMCDes.rad2005 = False
userMCDes.radNew = False
userMCDes.Size = New System.Drawing.Size(624, 117)
userMCDes.TabIndex = 402
userMCDes.TextAFCLRV = ""
userMCDes.TextC1 = ""
userMCDes.TextC2 = ""
userMCDes.TextC3 = ""
userMCDes.textCalNet = ""
userMCDes.TextD1 = ""
userMCDes.TextD2 = ""
userMCDes.TextD3 = ""
userMCDes.textDaysOwed = "9"
userMCDes.textEndDate = ""
userMCDes.textExpdate = ""
userMCDes.textInitialUse = ""
userMCDes.textpostdate = ""
userMCDes.TextSerialNum = ""
userMCDes.TextT1 = ""
userMCDes.TextT2 = ""
userMCDes.TextT3 = ""
userMCDes.WhereRept = 0
PanelDes.Controls.AddRange(New Control() {userMCDes})
AddHandler userMCDes.Leave, AddressOf UserMCDes0_Leave

But when I clear the control (using PanelDes.ClearControl()) inside the panel and add the new control, it does get added...
And if I add the control to the form directly (using Me.Controls.Add(userMCDes)), it gets added too...
Please advice... what am I missing here???
 
Back
Top