Guest cgchris99 Posted October 16, 2002 Posted October 16, 2002 I am trying to loop thru all the controls that are in a groupbox. Here is what I am trying. This is my test code for debuggin. Dim ctl as Control Dim x as integer x=form1.instance.GroupBox2.Controls.Count() For Each ctl in Form1.instance.GroupBox2.Controls myname=ctl.name next x reports back 76 So I would expect the for loop to loop 76 times. It only loops once. Why is this? I don't know if this helps. But the GroupBox2 is actually on a TabPage also. Thanks Quote
*Gurus* divil Posted October 16, 2002 *Gurus* Posted October 16, 2002 It ought to loop however many times there are controls in the groupbox. I see no code for counting the number of loops, so how do you know. You step through it? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest cgchris99 Posted October 16, 2002 Posted October 16, 2002 Yes, I am stepping through it with the debugger. That's how I know it is only happening for one control. Quote
*Experts* Bucky Posted October 16, 2002 *Experts* Posted October 16, 2002 In the declaration of the loop: For Each ctl in Form1.instance.GroupBox2.Controls I'm pretty sure you need to declare a new instance of Form1, and then loop through that. Dim ctl as Control Dim x as integer Dim f As New Form1() x=f.GroupBox2.Controls.Count() For Each ctl in f.GroupBox2.Controls myname=ctl.name next Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
duncallen Posted October 16, 2002 Posted October 16, 2002 (edited) Sorry for the horrible naming conv. this works in Net for me the groupbox has its own controls collection which all objects are added to when they are placed in the groupbox Dim ctr As Control For Each ctr In Me.GroupBox1.Controls If TypeOf ctr Is Label Then ctr.Text = "Cool" End If Next therefore if you can reference the groupBox object you can refer to its collection property [edit] or loop through collection using the .item[/edit] Dim ctr1 As Control Dim i As Integer Dim l As Integer i = GroupBox1.Controls.Count If i > 0 Then For l = 0 To (i - 1) ctr1 = GroupBox1.Controls.Item(l) Next End If Edited October 16, 2002 by duncallen Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.