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

programmatically adding checkboxes

Status
Not open for further replies.

glamb

Programmer
Dec 29, 2009
32
US
I want to create dynamic checkboxes on my form to accommodate the addition of a new client without having to change code. The problem I'm having is that after I programmatically create 7 checkboxes in the form init method, including one that will process all the clients, I don't know where to put the 'CLICK' method code for each checkbox. For instance, when the 'ALL' checkbox is clicked how would I set all the individual checkboxes?
 
You cannot add code to an instance created on the fly. Instead of using baseclass checkboxes, create your own checkbox class and add that to your form instead.

In your form checkbox class' click method you could do something like:

thisform.MyMethod(this)

Inside your form's MyMethod, add a CASE for each checkbox and put the code there.
 
Glamb,

Presumably, there is a limit to the number of checkboxes you will create on any given instance of the form.

If that's so, an easy solution would be to create the maximum number of checkboxes at design time, and to make them initially invisible. Then, each time you need to add a new client, just make one of the checkboxes visible again.

That way, you will have access to all the properties, events and methods of all the checkboxes at design time, so there will be no problem in knowing where to put the code.

Also, you asked how to implement the "All" checkbox. You need some code similar to the following in its Click event:

Code:
FOR EACH oControl IN Thisform.Controls
  IF LOWER(oControl.BaseClass) = "checkbox"
    oControl.Value = This.Value
  ENDIF
ENDFOR

This wil set every checkbox on the form to the same value as the "All" checkbox. (You would need to modify the code slightly if there were other checkboxes that you didn't want to treat in this way. Aslo, I'm assuming that the checkboxes are placed directly on the form, not in a pageframe or other container.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks, both of you. Both solutions would work for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top