Henrique Muzzi Henrique Muzzi -3 years ago 93
Vb.net Question

VB.NET Iteratin to Disable Controls and Them Enabling some of them

I am trying to disable all controls in a form on .Load, except for a few. Since I am disabling a lot of controls and enabling only a few, I did not use something like if TypeOf Control Is ComboBox then... in my loop. I will just enable them one by one.

My problem is that when I enable them right after the loop, only the menustrip and button will work. Other (comboboxes and textboxes) will remain locked.

Here's this part in my code:

Private Sub AddForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim addformcontrol As Control
For Each addformcontrol In Me.Controls
addformcontrol.Enabled = False

someComboBox.Enabled = True
someTextBox.Enabled = True
MenuStrip1.Enabled = True
CleanAllButton.Enabled = True

End Sub


Answer Source

If these controls are in a container, such as a groupbox, and that control is disabled, enabling the child controls won't do the job.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download