Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable A Group of CheckBoxes 2

Status
Not open for further replies.

reffek

Programmer
Apr 7, 2005
24
0
0
US
What's I'm trying to do is disable and enable a group of checkboxes. I keep getting a stack overflow error.

Code:
If chkStatusAll.Checked Then

    For Each controlItem As CheckBox In grpStatus.Controls
        With controlItem
            .Checked = False
            .Enabled = False
        End With
    Next
    chkStatusAll.Enabled = True
    chkStatusAll.Checked = True

Else

    For Each controlItem As CheckBox In grpStatus.Controls
         With controlItem
              .Enabled = True
              .Checked = False
         End With
     Next
     chkStatusAll.Checked = False

End If
 
what events are associated with that sub? What happens is when you programmaticaly change the check value of a check box, it fires the event that runs that procedure. Which then changes the check box which fires that procedure. Which then changes the check box which fires that procedure. Which then changes the check box which fires that procedure. errr, you get the idea.

Code:
'class level variable
dim DoNotCheck as boolean = false


'inside your procedure
If not DoNotCheck then
  DoNotCheck=true
  If chkStatusAll.Checked Then

    For Each controlItem As CheckBox In grpStatus.Controls
        With controlItem
            .Checked = False
            .Enabled = False
        End With
    Next
    chkStatusAll.Enabled = True
    chkStatusAll.Checked = True

  Else

    For Each controlItem As CheckBox In grpStatus.Controls
         With controlItem
              .Enabled = True
              .Checked = False
         End With
     Next
     chkStatusAll.Checked = False

  End If
  DoNotCheck=false
end if

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Code:
If chkStatusAll.Checked Then
    For Each controlItem As [b]Control[/b] In Me.grpStatus.Controls
      If typeOf controlItem Is CheckBox Then
        With controlItem
            .Checked = False
            .Enabled = False
        End With
      End If
    Next
    chkStatusAll.Enabled = True
    chkStatusAll.Checked = True
Else
    For Each controlItem As Control In Me.grpStatus.Controls
      If typeOf controlItem Is CheckBox Then
         With controlItem
              .Enabled = True
              .Checked = False
         End With
      End If
     Next
     chkStatusAll.Checked = False
End If


-bclt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top