I have a simple vb 2010 form that I want to be able to set the enabled stated of all buttons on.
I have made similar functions for checkboxes and numericalUpDown controls that function as required, but for buttons the function does not seem to operate correctly.
Private Sub setButtonsState(ByVal state As Boolean)
Dim cControl As Control
For Each cControl In Me.Controls
If (TypeOf cControl Is Button) Then
cControl.Enabled = state
End If
Next cControl
End Sub
Which is called like so: setButtonsState(True)
This doesnt seem to have any effect at all with buttons, though buttonName.Enabled = True works OK…
Im pretty much what you’d call a noob at VB, so anyone help me out?
Ta
Unless all of your buttons belong directly to the Form this is run in, then they won’t be accessed because this doesn’t cruise down through the control tree to get to them. A slightly different approach might be a more recursive method: