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

Visual effect of Option Button bound to a character field 2

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,
I have an optiongroup which is bound to a character field.
Don't seem to find a way to have the optionbutton bound to the expression in the character field to show .t. (big dark center dot) or .F. (no dot). Cant find the property which controls this. Do we have a solution for this?

Option1.Caption ="Black"
Option1.Value = 0
Option2.Caption ="White"
Option2.Value = 0
OptionGroup.Value = [NONE]

Upon click of an option button the value of myField is the value of the Caption. He the physical effect is not activated

Trust I have made myself clear.
Thks,
Jockey(2)

 
I'm not sure what you're trying to acheve here, but I think you're trying to get the button caption to change?

Assuming you have a "MyGroupBase" (sub-class of the base class Group:

If it's the first button, from the Group's Init you could set:

This.COMMAND1.Caption = "Black"
This.COMMAND2.Caption = "White"

You don't seem to be following down the object path. If you put This.Caption at the Group object level, it's going to apply it to that object, and not the child objects.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
optiongroup.value always has to be the number of the option to select or selected, there is no way to bind char values to set the option with the corresponding caption, there is no such binding.
Optiongroups work like an enum of captions, but the value you get and set is the option number, not the caption text.

Bye, Olaf.
 
Ah, like radio buttons...

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Hi,
Yes in VFP they call radiobuttons option group.
OptionGroup_qvqad5.png


What I am trying to achieve is to have the button black as in above picture for option black when the bound field cColour has value 'black'

It is very well possible to have an optiongroup.controlsource set to an character type field. I agree usualy one bounds it to a numeric or integer field. Please read also .

So I don't want to change the optionsGroup options style to 1, it should remain 0.

Trust now clear.

Rgds,
Jockey(2)
 
Right, easy one.

Refresh Clause of the Option Group (as you call it) put in:

IF cColour = "Black"
This.Value = 1​
ELSE
This.Value = 2​
ENDIF

Or in the Form's Refesh you can say:
IF cColour = "Black"
ThisForm.RadioButton.Value = 1​
ELSE
ThisForm.RadioButton.Value = 2​
ENDIF


Or if you expect more colors make it a CASE and just match them to their position:

DO CASE
CASE cColour = "Black"
This.Value = 1
CASE cColor = "White"
This.Value = 2
Case cColor = "Pink"
This.Value = 3
ENDCASE

(Etc).

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Oh and just one other point:

I have an optiongroup which is bound to a character field.

Actually, you don't. The control stores a numeric value, not a character one. Which is why set their value in the way that I've described.
You can check it, with this in say, your Form's INIT:

MESSAGEBOX(ThisForm.Optiongroup.Value) you will see that it will return "1" and not "Black" as you have set the caption on the option button. What you are trying to achieve is to position the active value (effectively click the button) programmatically. And to do that, you have to give it the value of the position (which is actually the "Tabindex" property value of the control). The Group's "Value" corresponds to the Option's TabIndex. So by setting the Value of the Group Object, it selects them by order. You can rearrange them inside the group box, and that won't change their tab index. So be careful with it if you have a lot, and swap their order around later, it can get a bit confusing.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
The simplest solution would be saving the option number as key in the data, better yet also have a table with the option number as it's key and the captions in a secondary field. At least you could define some constants eg #DEFINE BLACK 1, #DEFINE WHITE 2, but the table with this list of values could even drive building the optiongroup by the data, using it as meta data. Or use a combobox instead, but there often is a reason you want radiobuttons, for example to see all options. Typically you also do this with few options. a Listbox would also be an alternative showing all "options" as all its items. The optiongroup has one big benefit, if you combine it with a background picture you can for example set the circles to some cities or regions of a map.

Bye, Olaf.
 
Olaf,
Your point about using option group circles with maps is a cool idea... I might use that.
What you mention about tableizing and matching is what I do... but I think Jocky2 is still making his way, so didn't want to overwhelm him with these concepts. If he only has 2 options Black/White is easy enough to manage for now. (just a thought)


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Hi Scott

So I issued

Code:
IF cColour = "Black"
[indent][/indent]This.Value = 1
ELSE
This.Value = 2
ENDIF

I can see in the debugger that this effects to change also cColours into "1" - how Fox transfers my 1 into "1" dont know.
end result is that cColours is not changed ans remains as original. ;(

Rgds,

Jockey(2)

 
In the firs place you have to remove the binding to the cColor field, as it doesn't work.
Then the refresh can set the value and the value can cause the right option to be highlighted.

Bye, Olaf.
 
I never taught this is possible, but I've tried, and you can use as controlsource for optiongroup, a character field.
The value of optiongroup is the caption of the buttons, and the field is updated with the caption...but with a step behind.

Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("myform")
ofrm.show()

DEFINE CLASS myform as Form
	ADD OBJECT opt as optiongroup WITH autosize = .t., buttoncount = 3, controlsource = 'cc.cColor'
	ADD OBJECT txt as textbox WITH top = 100
	PROCEDURE load
		CREATE CURSOR cc (cColor C(10))
		INSERT INTO cc  VALUES ('Black')
	ENDPROC
	PROCEDURE init
		This.opt.Buttons[1].Caption = 'Black'
		This.opt.Buttons[2].Caption = 'White'
		This.opt.Buttons[3].Caption = 'Yellow'
		This.opt.Setall('autosize',.t.)
	ENDPROC
	PROCEDURE opt.interactivechange
		ACTIVATE SCREEN
		?This.value
	ENDPROC 
ENDDEFINE


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
There's a lot of wrong information in this discussion. OptionGroups have always been able to have a character value that matches the prompt of the selected item.

Tamar
 
Dear Tamar,

I was aware of that dont know why Olaf kept on insisting it was not possible, probably he misunderstood me. I only could not find a simple method to make the atual option value visible.
Vilhelm gave me a working sample and thus I became aware that in case the caption is longer than the bound fields it will not substring to the width, it will simply not 'work'.
( field width = 2, caption is "Black", in the debugger you notice for the field.value "Bl", however not in the table and thus the Option button does not show 'selected' )

See the effect with Vilhelm's sample after you changed: Create Cursor cc (cColor C(10)) into Create Cursor cc (cColor C(3))

Regards,
Jockey(2)
 
Jokey2,
Fox doesn't fix variable types. So if you assign lcVar = "MyVar" and the assign lcVar = 2 it doesn't complain, and will happily accept the different variable type. This is true of all variable and variable types in Fox leading back to FoxBase. It's one of those things you either love or hate. Depends on what you were brought up on.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top