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!

Enable/disable multiple objects simultanously?

Status
Not open for further replies.

EMJULIAN

Programmer
Aug 14, 2002
45
0
0
US
Is there a way to enable/disable multiple objects on a form simultanously? I want to have several objects disabled until the user clicks a button and then have them all enable without having to code in every single "enabled=.t.".

Thanks!
Eve
 
EMJULIAN

Group your controls by using:
Thisfrom.setall("Enabled",.t.,"TextBox")

That will take care of all the textboxes with one line. Do the same for all other controls on your form.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
If you wish to have a bit more control you can add code to do it.

Code:
lcAllowEdits = [.T.]
FOR EACH loTxt IN THISFORM.pgfMain.page1.objects
  IF INLIST(UPPER(loTxt.baseClass),[TEXTBOX],[EDITBOX],[LISTBOX])
    lcCmd = "THISFORM.PgfMain.page1." + loTxt.Name + ".ENABLED = " + lcAllowEdits 
    &lcCmd
  ENDIF
ENDFOR

Pass in the lcAllowEdits as a parm. It must be character because you are building the command & executing it each time.


Jim Osieczonek
Delta Business Group, LLC
 
Hi Eve,

When you say "several objects" I presume you don't mean a very large number of them. So I'm not sure what the problem is in coding "several" lines as in:

WITH thisform
.object1.ENABLED = .F.
.object2.ENABLED = .F.
.object3.ENABLED = .F.
.object4.ENABLED = .F.
.object5.ENABLED = .F.
.object6.ENABLED = .F.
.object7.ENABLED = .F.
.object8.ENABLED = .F.
ENDWITH

I prefer this type of approach because (IMO) the code is clear.

Jim
 
If you include them in a container of some kind (say a page frame) you could disable that and the contents would be disabled at the same time.

Regards

Griff
Keep [Smile]ing
 
You could also use an actual container shape too.

Snag is they won't LOOK disabled

Regards

Griff
Keep [Smile]ing
 
Hello Eve

I alwayss prefer th OOP approach. I have one class for each input objet ie Forms, textBox, combobox, grid etc.

In the form class, I've put a cFormStatus properties (init to blank).

In the refresh() of all input class (textBox, combobox, grid), I've put the code ;

THIS.ENABLED = NOT EMPTY(THISFORM.cFormStatus)

Now, in the form, I have one command button (cmdEdit) with this code in the click even

THISFORM.cFormStatus = "EDIT"
THISFORM.REFRESH

And an other command button (cmdSave) with this code in the click even

THISFORM.cFormStatus = ""
THISFORM.REFRESH

Each time the user clik on cmdEdit, all the controls on the form are active. When he click on cmdSave, all the controls are deactivated.

I hope this help.

Nro



 
Gosh! Some really great ideas from my peers!

imho, I agree with the clarity issue that jimstarr raised.

WITH thisform
.object1.ENABLED = .F.
.object2.ENABLED = .F.
.object8.ENABLED = .F.
ENDWITH

My solution was to define a method on the form and pass it a logical variable. Hope my 26 roots don't show 2 much....

method = "tShowGets"

called as...

thisform.tShowGets(.F.)

tShowGets
PARAMETERS x

ThisForm.Cmbww1.ENABLED=x
ThisForm.Cmbww2.ENABLED=x
ThisForm.txtDdate.ENABLED=x
ThisForm.txtCphone.ENABLED=x
ThisForm.txtCfax.ENABLED=x
ThisForm.txtCemail.ENABLED=x


HTH - Wayne

 
Hi Eve,

You are using sub classes, aren't you? If so you should be able to add a property, set it .T. or .F., and iterate through it using PEMSTATUS checking that the property exists to enable or disable.

I haven't actually tried it, but it should work.

Regards,

Mike
 
Oops, sorry!

Iterate through the controls collection. Too much whiskey.

Have a good day,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top