Microsoft KB Archive/138920

= How to Enable One Check Box While Disabling the Others =

Article ID: 138920

Article Last Modified on 2/11/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q138920



SUMMARY
Multiple check boxes are often necessary to gather required input. Frequently, it is desirable to disable the unselected check boxes after the first check box is selected. The example in this article illustrates how to disable the unselected check boxes in a form.

Although option (also known as radio) buttons are generally the preferred of allowing users to make only once choice among a group of choices, this article provides an alternative method of doing so using check boxes.



MORE INFORMATION
The form created by the following example contains three check boxes. When a check box is selected, its Value property is set to 1. After checking the Value property in the Click event of each individual check box, the Enabled properties of the remaining check boxes are changed to false (.F.). Changing these properties disables the check boxes.

Step-by-Step Example
 Create a new form, and name it Test.scx. Place three check boxes on the form by using the Form Builder.  In the Refresh event of the form, place the following code: IF ThisForm.Check1.Enabled=.t. and ThisForm.Check1.Value=1 ThisForm.Check2.Enabled=.f.      ThisForm.Check3.Enabled=.f.   ENDIF

IF ThisForm.Check2.Enabled=.t. and ThisForm.Check2.Value=1 ThisForm.Check1.Enabled=.f.       ThisForm.Check3.Enabled=.f.   ENDIF

IF ThisForm.Check3.Enabled=.t. and ThisForm.Check3.Value=1 ThisForm.Check1.Enabled=.f.       ThisForm.Check2.Enabled=.f.   ENDIF

IF ThisForm.Check1.Enabled=.t. and ThisForm.Check1.Value=0 ThisForm.Check2.Enabled=.t.      ThisForm.Check3.Enabled=.t.   ENDIF

IF ThisForm.Check2.Enabled=.t. and ThisForm.Check2.Value=0 ThisForm.Check1.Enabled=.t.      ThisForm.Check3.Enabled=.t.   ENDIF

IF ThisForm.Check3.Enabled=.t. and ThisForm.Check3.Value=0 ThisForm.Check1.Enabled=.t.      ThisForm.Check2.Enabled=.t.   ENDIF   In the InteractiveChange event of each check box, add the following line of code: ThisForm.Refresh  If you want the disabled check boxes to appear in a different color, set the DisabledBackColor property for each box. The box will automatically change color when disabled. Save and run the form. Click any check box to select it, and the remaining check boxes are disabled. Click the check box a second time to clear it, and the other check boxes are reenabled.</li></ol>

Additional Notes

 * Changing the BackColor property to gray emulates a disabled check box in FoxPro 2.x for Windows.
 * Typing Help Backcolor in the Command window provides a list of colors and their corresponding numbers.

<div class="references_section">