Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding custom optionbuttons to optiongroup
Message
From
14/04/1998 17:20:17
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Adding custom optionbuttons to optiongroup
Miscellaneous
Thread ID:
00091946
Message ID:
00091946
Views:
75
A sligt problem, similar to having to add your own cell controls to a grid; now it's a bit different: I need to have my option buttons in an option group, because of the need to handle keypress individually. OptionGroup doesn't have a keypress of its own, but option buttons do. The trouble is that I'm quite accustomed to have these populated at runtime, like this:

*
 optiongroup.init:
External array vrana_l
with this
	.width=0.1
	.buttoncount=alen(vrana_l)
	for i=1 to .buttoncount
		.buttons(i).caption=vrana_l(i)
		.buttons(i).BackStyle=0
		.buttons(i).ForeColor=0xFFFFFF
		.buttons(i).FontBold=.t.
		.buttons(i).FontName=g_fontname
		.width=max(.width, .buttons(i).left+.buttons(i).width+.2)
	endf
	.height=.buttons(.buttoncount).height+.buttons(.buttoncount).top+.2
endwith
So far so good, this part works. The trouble is that setting just the .buttoncount automatically adds new buttons of class OptionButton, not my class at all. My optiongroup class has one button, and I've tried removing it and adding one from my class library, and it complains saying "can't add an object to a non-container class". Super. Now OptionGroup is not a container - it just looks like one and has a buttoncount property. I wouldn't like to code each button's KeyPress - I'd like to do it at class level. Adding code to the initially contained button fires on that button only, the other buttons react as default.

I see several ways out of this:
- create a 25-button optiongroup class (25 seems to be the magic number) and copy the code into each of the buttons
- fiddle with VCXeditor and substitute the classname of the optionbutton in the optiongroup class, and enter the code only once, in the optionbutton class., and then set the optiongroup class to have 25 buttons, hoping they will be of MyOptionButton class, and not default.
- do any combination of the two
- write a builder which will search for optionbuttons on a form and insert necessary code.

All of these approaches are pure OOP all the way, from the first coach on ; >

I tried the VCXeditor approach: increased the number of buttons in the optiongroup, then opened the properties and added Option2.Class = "gradio_b" for each of the optionbuttons. Next time I opened it in class designer, all the buttons reverted to being of class "optionbutton". No good at all. Seems to be I'll have to replicate the code to each of the 25 buttons individually, which is... not like working on a computer at all. Looks like knitting. Of course, I'll have to propagate any of the changes to all of the buttons, that's called maintenance. OK, I'll make it a call to the optiongroup's custom method, so I do this only once. Still I think this is way too clumsy.

Before anybody asks me why do I need this: FPD radio buttons reacted fine on Enter. Now they don't give a damn - the default nav button (save, in this case) fires first. OK, textbox behaved the same way, but just a little

case nKeycode=13
clea type
keyb '{tab}' plain
nodefault
in the textbox class .KeyPress took care of that; now for button groups it seems to be rather more complicated.

FoxWish: Default Command Buttons should receive the Enter key only if the command group (any of the buttons) has the focus, or at least there should be a property IsDefaultToForm, which I'd be happy to set to .f.

Anyway, even if the problem of nav buttons catching enter whenever they want gets solved, still another one remains - the button groups (and grids likewise) don't have a way we can add our own class as their contained objects.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Next
Reply
Map
View

Click here to load this message in the networking platform