enable/disable very many things at one time

I have an on-line support forum… inside the software.
First, you select language. Then each thread or begin a new thread. (You get the idea, it’s nothing weird…)

In the beginning, all fields and buttons are disabled, because you need to choose a language before adding a post. (Or, choose a thread to add a reply.)

Is there a way to add many items to a collection and then simply disable / enable this collection rather than each individual object!?

I think RealBasic used to have such feature in the IDE… maybe it’s still there and is possible to use, with code?

You mean enable disable controls? You can create a control set and enable/disable every member in a for/next loop. You can create a control set by creating a minimum of two controls and giving them the same name. The IDE will ask you if you want to create a control set…

Or programmatically you could use an interface that enables/disables all connected controls.

For disparate control types or if you don’t want them in a Control Set you can add them all to an array of a common type then loop on that array.

[code]Property postControls() As WebControl

Sub Open
postControls.Append postButton
postControls.Append postTitleField
postControls.Append postBodyTextArea
//… etc for all controls to enable/disable
End Sub

Sub setPostControlsEnabled(newState As boolean)
for i As integer = 0 to postControls.Ubound
postControls(i).Enabled = newState
End Sub[/code]

setPostControlsEnabled(true) //enables all of them setPostControlsEnabled(false) //disables all
For a desktop project use RectControl instead of WebControl.

Or just put all in a GroupBox and disable /enable the whole GroupBox

Is that possible!?Because it’s actually the design I have! :slight_smile:

I was also thinking:

Such kind… and put all ON/OFF code in there.

Yes, it is. I’ve not tested it but it should also work with Containers or PagePanels.

I’m trying to Enable and Disable all controls in the window. There is a way to do that instead doing one-by-one? I can’t use control sets in this case because I need to do it in all control types of my window.
Thanks in advance.

just curious… did you bother reading the posts that came before yours?

This is a very old thread, but in case someone else is searching for an answer to this question…

I just finished struggling with the above suggestions and others I found elsewhere. I just now figured out a simple solution…

I created a method named enableDisableControls in each container where I wanted all the controls to be disabled, passing the desired enable state, true or false…

\\Method: enableDisableControls
Dim i As Integer
Dim c As WebControl

For i = 0 to self.ControlCount - 1
if self.ControlAtIndex(i) isa WebControl then
c = WebControl(self.ControlAtIndex(i))
c.Enabled = state
end if



Call it like this…


Most important is that this method must bd a method in the target container.

Thing I had trouble getting my head around is that ControlAtIndex always returns a WebObject not a WebControl. A WebObject is the super class for all web controls. A WebObject does not have an enabled property. So self.ControlAtIndex(i)) does not have an enabled property and thus the subclass WebControl must be addressed instead. I cannot find documentation for WebControl() but it obviously returns the WebControl sub class of the WebObject.

You can easily modify this to target specific controls with any number of ifs like c.name <>,“myListBox”, or c isa WebListBox.

Cool idea, John. For kicks I redesigned it as an assignment. This version, you use like this:

SomeWebContainer.AllControlsEnabled = false
Public Sub AllControlsEnabled(extends toContainer as WebContainer, assigns bValue as Boolean)
  dim tiMax as Integer = toContainer.ControlCount - 1
  for tiControl as Integer = 0 to tiMax
    if toContainer.ControlAtIndex(tiControl) isa WebControl then
      WebControl(toContainer.ControlAtIndex(tiControl)).Enabled = bValue
  next tiControl
End Sub

You could probably override it with the same thing but passing a WebPage for more fun. :slight_smile: