litesh80 Posted August 25, 2005 Posted August 25, 2005 I have 20 check boxes in a form. and I have 20 textboxes in another form. now my requirement goes as follows. On clicking a button all the checkboxes should go checked or uncheked. All this should happen in one loop. The same requirement goes for clearing textboxes in next form. Suggestions are appreciated. Quote
mark007 Posted August 25, 2005 Posted August 25, 2005 I would loop through the controls on the form and check the type of the control. If it's a checkbox then check it. :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
FYRe Posted August 26, 2005 Posted August 26, 2005 (edited) For Loop To do so in a loop is possible, but I can't recall how to. :D You'll need to do so using a for loop. Despite unable to recall, I did a solution (see attached file). Though it seems quite long, it's just one of the many ways that work. I'd be glad if someone could come up with a solution to this problem too. I'd like to find out about it too....WindowsApplication1.zip Edited August 26, 2005 by PlausiblyDamp Quote sOMEONE'S gONNA dO iT, wHY nOT yOU ?
thenerd Posted August 26, 2005 Posted August 26, 2005 dim Chk as checkbox for each chk in me.controls chk.checked = true next chk Dim chk As New CheckBox For x As Integer = 0 To Me.Controls.Count - 1 If Me.Controls(x).GetType Is chk.GetType Then CType(Me.Controls(x), CheckBox).Checked = True End If Next chk.Dispose() Both work. By the way: In the future, take the .exe's out of your attachments (There's one in the bin folder and one in another folder). I'm not sure about this forum, but most forums don't allow attachments that include .exe's. Quote
FYRe Posted August 26, 2005 Posted August 26, 2005 Well, did you know that you could atually zip the .exe file? So, .zip is acceptable =) Quote sOMEONE'S gONNA dO iT, wHY nOT yOU ?
mark007 Posted August 26, 2005 Posted August 26, 2005 Or to throw another way: Dim c As System.Windows.Forms.Control For Each c In Me.Controls If TypeName(c) = "CheckBox" Then CType(c, CheckBox).Checked = True End If Next :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
litesh80 Posted August 26, 2005 Author Posted August 26, 2005 None of ur methods worked... Thank you for ur response. But Unfortunately I could not work out with either ways u have mentioned. Provide some better way. Quote
litesh80 Posted August 26, 2005 Author Posted August 26, 2005 Not working It's not working... Or to throw another way: Dim c As System.Windows.Forms.Control For Each c In Me.Controls If TypeName(c) = "CheckBox" Then CType(c, CheckBox).Checked = True End If Next :) Quote
litesh80 Posted August 26, 2005 Author Posted August 26, 2005 Second one worked fine when i did it in a new window. Now I'll have to try it on the original project. Anyway I'll check it out. Thank you again. Quote
litesh80 Posted August 26, 2005 Author Posted August 26, 2005 All are working fine when the Controls are directly on to the form. But I am using 5 groupboxes in which i am placing the controls. Its not working.... Quote
Administrators PlausiblyDamp Posted August 26, 2005 Administrators Posted August 26, 2005 If the controls are in a groupbox then you will need to loop through the groupbox's controls collection rather than the form's control collection. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mark007 Posted August 26, 2005 Posted August 26, 2005 Or use recursion to get all the controls: CheckBoxes(Me) Private Sub CheckBoxes(ByVal Parent As System.Windows.Forms.Control) dim c As System.Windows.Forms.Control For Each c In Parent.Controls CheckBoxes(c) If TypeName(c) = "CheckBox" Then CType(c, CheckBox).Checked = True End If Next End Sub :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
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.