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

Interesting Problem

Status
Not open for further replies.

Serincino

Programmer
Jun 13, 2003
61
US
On my form I have 2 checkboxes that are attached to a Logical Data field. Date Source for one check box is thislogicalfield while the other is !thislogicalfield when the form is first shown the checkboxes are readonly. When the user clicks the edit button the checkboxes are set to readonly = .f. by using setall thisform.setall('readonly',.f.,[checkbox]). The problem is that the checkbox that has a data source of !thislogicalfield stays readonly while the other can be changed.
Does anybody know why this is happening? My users need the two checkboxes one for yes the other for no.
Thanks for any help you give me in advance.

-Serincino

If you see a programmer in the office before 9am, they probably never left.
 
Yes, the checkbox with the datasource set to !thislogicalfield stays read-only because you are using an expression in the datasource rather than a variable name or field name...If you think about it, what is VFP suppose to do if it were to make the checkbox read/write...I mean if the user sets or clears the checkbox VFP has nowhere to put that information, since it cannot store a value to an expression....it is no different than if in code you were to write:

!thislogicalfield = .T.

...this is obviously not a legal assignment statement. I hope I've explained this clearly, sometimes I can be a bit wordy. [smile]

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
ok, that all makes sense. the the problem becomes how do I get the desired effect I'm looking for? I was orginally trying the idea of option buttons, but their values can only be numberic and not true false.

-Serincino

If you see a programmer in the office before 9am, they probably never left.
 
Serincino,

Try to use "Enabled" properties instead.

-- AirCon --
 
Well, you could certainly create a variable to be used by an optiongroup, call it nLogicalField and use it as the controlsource for the optiongroup....then in code you would have to set the value based on your logical field such as

nLogicalField = iif(thislogicalfield, 1, 2)

...and in the interactivechange event of the option group you could replace your field accordingly...

Replace thislogicalfield with (this.value = 1)

...this is just one thought, there are many ways to skin a fox.

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
Something like this might work ...


Create an invisible checkbox with control source assigned to the field you are controlling.

Then put in 2 check boxes with no control assigned.

checkbox1.click
if this.value
thisform.invisibleCheckbox.value = .t.
thisform.checkbox2.value = .f.
endif
checkbox1.refresh
if thisform.invisibleCheckbox.value
this.value = .t.
else
this.value = .f.
endif



checkbox2.click
if this.value
thisform.invisibleControl.value = .f.
thisform.checkbox1.value = .f.
endif
checkbox2.refresh
if thisform.invisibleCheckbox.value
this.value = .f.
else
this.value = .t.
endif


Don


 
It seems like the user interface you're trying to simulate would best be served by an option group control (radio buttons) instead of two checkboxes. Your two options are mutually exclusive (you can have either one checked, but not both) so it seems like this would make more sense to users. The only trick would be to translate the numeric value of the option group (1 or 2) to the logical value that you want to save.

Say you have an option group with ButtonCount=2, with the two options labeled "Yes" and "No", or "True" and "False" - you could leave the ControlSource property blank, but then put code in the Init method of the form to set the control value based on the value of the initial value of the logical property (i.e., THIS.opgControl.Value = IIF(THISFORM.lLogicalProperty, 1, 2) ). Then you could put code in the InteractiveChange method of the option group to set the logical property based on the value. (i.e., THISFORM.lLogicalProperty = (THIS.Value == 1))

I tried it on a form here, and it seems to work fine.
 
Thank all of you for your help. I used the idea of the invisible checkbox attached to the control, theing using, refreshs, programmatic and interactive changes.

Again many thnaks for all the help.

-Serincino

If you see a programmer in the office before 9am, they probably never left.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top