Controls.Add not updating Collection 
Author Message
 Controls.Add not updating Collection

Hello,

I'm using code similar to the following to add controls to
a panel on a form in VB.NET.  

Dim chkNewCheckBox As New System.Windows.Forms.CheckBox()
chkNewCheckBox.Size = New System.Drawing.Size(200, 30)
chkNewCheckBox.Location = New System.Drawing.Point(250, 40
+ intControlCount * 40)
chkNewCheckBox.Name = "chk" & Replace(prsUserFields.Fields
("KeyField").Value, " ", "_")
chkNewCheckBox.Text = prsUserFields.Fields("Prompt").Value
Me.Controls.Add(chkNewCheckBox)
'add the click event and point to existing click event
AddHandler chkNewCheckBox.Click, AddressOf
CheckBox1_CheckedChanged

Me.pnlScreen.Controls.AddRange(New
System.Windows.Forms.Control() {chkNewCheckBox})

The controls and their event handlers work.  In the form
activiate event I'm then trying to loop through all the
controls and set their values, but they don't show up when
I do a:

For Each lControl In Me.Controls

Only the controls that were added at design time show up
in the Controls collection.  Any idea what's wrong?

Thanks,
Eric



Sat, 11 Jun 2005 04:07:48 GMT  
 Controls.Add not updating Collection
That is because you are adding this object to the Controls collection of
pnlScreen, not the window. You need to look in this collection in order to
see your object.


Quote:
> Hello,

> I'm using code similar to the following to add controls to
> a panel on a form in VB.NET.

> Dim chkNewCheckBox As New System.Windows.Forms.CheckBox()
> chkNewCheckBox.Size = New System.Drawing.Size(200, 30)
> chkNewCheckBox.Location = New System.Drawing.Point(250, 40
> + intControlCount * 40)
> chkNewCheckBox.Name = "chk" & Replace(prsUserFields.Fields
> ("KeyField").Value, " ", "_")
> chkNewCheckBox.Text = prsUserFields.Fields("Prompt").Value
> Me.Controls.Add(chkNewCheckBox)
> 'add the click event and point to existing click event
> AddHandler chkNewCheckBox.Click, AddressOf
> CheckBox1_CheckedChanged

> Me.pnlScreen.Controls.AddRange(New
> System.Windows.Forms.Control() {chkNewCheckBox})

> The controls and their event handlers work.  In the form
> activiate event I'm then trying to loop through all the
> controls and set their values, but they don't show up when
> I do a:

> For Each lControl In Me.Controls

> Only the controls that were added at design time show up
> in the Controls collection.  Any idea what's wrong?

> Thanks,
> Eric



Sat, 11 Jun 2005 04:25:44 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ? Collection add object -> usercontrol add control

2. ? Collection add object -> usercontrol add control

3. Dynamically adding controls to the Controls collection

4. ADOX Catalog.Users collection not updated after delete

5. Problem adding to collection only when complied, not in IDE

6. Bound controls not updating ADO with adodc.recordset.update command

7. Collection.Add and Collection.Item question?

8. VBA Error Handler add-in will not update in Access 2000, Visual Basic Editor

9. oledb update command not inserting recently added row...

10. MSHFlexgrid not updating when adding records to Access Table

11. Adding Tables : SQL not updated

12. grid bound to a child table does not update with add

 

 
Powered by phpBB® Forum Software