11

I have total 4 radiobuttons on my form,I want to set the first two buttons in one group and the second two in another group so that I can check one from the first group and one from the second group.

Right now,if I check one from the first group,the one from the second group becomes unchecked.

I've always wondered how to do this and I believe now's the time to figure this out. :)

Ivan Prodanov
  • 34,634
  • 78
  • 176
  • 248

5 Answers5

17

To quote from the trusted Delphi 5 help:

By default, all radio buttons that are directly contained in the same windowed control container, such as a TRadioGroup or TPanel, are grouped. For example, two radio buttons on a form can be checked at the same time only if they are contained in separate containers, such as two different group boxes.

mghie
  • 32,028
  • 6
  • 87
  • 129
  • 1
    Agreed. Radiobutton grouping is based on Parent/Child relationships. In order to have multiple groups of buttons, you must use multiple Parent controls. – Remy Lebeau Aug 03 '09 at 23:17
3

Put two buttons on a panel, and the other two on another panel. That way, they will be treated as separate groupings. Change the panel bevels to remove the edge, and the four buttons won't look to the user as if they are separated, if that's what you'd like.

Kevin Killion
  • 123
  • 2
  • 9
1

A RadioButton does not have a GroupIndex Property, like the SpeedButton does.

It would be much more easier if it had, because you could use numbers to create sets of RadioButtons that interacts only with the ones of the same number set in the GroupIndex.

So all you can do is to out them inside a grouping control, like a Panel.

But you always could build your own version of a RadionButton with different new properties. :)

NaN
  • 8,596
  • 20
  • 79
  • 153
0

This is why we use Groupbox and Radiogroups (Can be found at standard controls). I recommend you to create 2 Groupboxes and put 2 radiobuttons in each one. Then you will be able to check 2 radiobuttons.

You can also choose a title for the groupbox. This is a very nice way to organise your application form

user2296565
  • 243
  • 1
  • 7
  • 18
0

That is great when Radio buttons of same group can be in rows or cols, but what if radio buttons must be shown in an X style (or in a more complex way):

 A B
 C D

Restrictions for that X style sample i put:

  • A has relation with D (A and D can not be checked at same time, checking one unchecks the other)
  • C has relation with B (C and B can not be checked at same time, checking one unchecks the other)

It is visually required as that, in an X style, so i can not put any GroupBox that holds that RadioButton, since GroupBox are rectangular, not diagonal.

I do not know any fix only using standard components, among there is a hack to make panels visually transparent and also click through able, so both panels are a square, one over the other.

But what about having the radio buttons very far one from the other,with a lot of complex components, flow panels, memos, etc?

The only option is to use third party components (at last up to what i know) or to do a lot of hard work:

  1. Create a panel for each RadioButton with exact same size and position as the RadioButton; this makes radio button to not uncheck any other, so more code is needed.
  2. Add code for each RadioButton, so when it is checked execute an uncheck on all the ones that are related with it (the ones that must not be checked at same time).

Too much work for something that could had been implemented on a simple property like RadioGroupIndex, if assigned a value of 0 then work as they work now, else uncheck only the ones for that same group... like on main menus.

claudio
  • 1
  • 1