Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted (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 by PlausiblyDamp
sOMEONE'S gONNA dO iT, wHY nOT yOU ?
Posted

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.

Posted

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

 

:)

Please check the Knowledge Base before you post.

"Computers are useless. They can only give you answers." - Pablo Picasso

The Code Net

Posted

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.

Posted

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

 

:)

Posted

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

 

:)

Please check the Knowledge Base before you post.

"Computers are useless. They can only give you answers." - Pablo Picasso

The Code Net

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...