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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling & Disabling Controls

Status
Not open for further replies.

Paladine

Technical User
Sep 16, 2001
26
CA
Ok, maybe I am going about this all wrong, but I am reasonably experienced with VBA/Access but I am trying to reproduce a form from it in VB.NET (after having read a VB.NET book...thought this would help me explorer my lack of knowledge) - I want to do the simple task of enabling and disabling controls, sometimes groups of controls, when certain events occur (i.e. cancel or search button click).

This is the code I used in VBA, what would be the same in VB.NET?

Dim ctrl As Control
For Each ctrl In Detail.Controls
If ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox Then
ctrl.Enabled = False
End If
Next

Groups of controls effected, except specific ones.

Thanks
 
Controls are in a collection in their parent control. There will be a separate collection for each container control, such as a Group control on a form and for the controls contained directly on the form, which itself is a control.

This works for the controls contained directly by the form.
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.GetType.Name.ToLower
Case = "textbox", "combobox"
......
End Select
Next

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
If you want to disable/enable controls on a form, including those contained within another control (such as a panel or groupbox) then use a recursive procedure:

Private Sub LockControls(ByVal ct As Control)

Dim child As Control

For Each child In ct.Controls

If TypeOf child Is Panel OrElse TypeOf child Is GroupBox Then LockControls(child, locked)

child.Enabled = False

Next

End Sub

To disable all controls on a form, call it using:

LockControls(Me)

or to disable all controls within a container (eg panel) use:

LockControls(pnlContainer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top