Recent

Author Topic: Radio Button Grouping?  (Read 15305 times)

Ruptor

  • Full Member
  • ***
  • Posts: 201
Radio Button Grouping?
« on: April 30, 2013, 02:07:23 pm »
Who is going to help a simple engineer to group a set of radio buttons so they don't change all the other radio buttons on my form? I have searched the forum and internet for several hours and can't even find an example that shows me how to do it let alone documentation that describes how to do it. This is the best kept secret on the net. I tried dropping a radio group box on the form then dropped the radio buttons on it but I can't see how to get them to link together.
If someone can just point me to the info it would be very helpful.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Radio Button Grouping?
« Reply #1 on: April 30, 2013, 02:22:21 pm »
You have two ways how to do it:
1) TRadioGroup: It has property Items. You can edit it and each line will become a radio button. Disadvantage of this solution: Items will not appear in *.po files (it is more difficult to translate the app.).

2) TGroupBox: You can put many TRadioButtons to many GroupBoxes. They will not affect each other.

EDIT: You can also use TPanel instead of TGroupBox.
« Last Edit: April 30, 2013, 02:25:03 pm by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Ruptor

  • Full Member
  • ***
  • Posts: 201
Re: Radio Button Grouping?
« Reply #2 on: April 30, 2013, 02:43:15 pm »
Sorry Blaazen I still don't understand. I see the items box under TRadioGroup but there is no items box under TGroupBox. Isn't there a graphical way to connect the radio buttons? I would have thought any radio button placed in a TRadioGroup box on the form would be seperate from the rest and have some identifier linking them.

goodname

  • Sr. Member
  • ****
  • Posts: 297
Re: Radio Button Grouping?
« Reply #3 on: April 30, 2013, 02:56:17 pm »
Set the parent of each TRadioButton in the same group to a single TGroupBox.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Radio Button Grouping?
« Reply #4 on: April 30, 2013, 03:00:24 pm »
Maybe a TCheckGroup would work better for what you are trying to do.  More that one box can be checked.
Lazarus Trunk / fpc 2.6.2 / Win32

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Radio Button Grouping?
« Reply #5 on: April 30, 2013, 03:03:25 pm »
Quote
I see the items box under TRadioGroup but there is no items box under TGroupBox.

TRadioGroup - you add radiobuttons via Items property.

TGroupBox or TPanel - you add radiobuttons directly from component palette.

And in code:

TRadioGroup - RadioGroup1.ItemIndex; - you can get Index of selected item (indexed from 0; -1 = no item selected)

TGroupBox or TPanel - you can access to every single TRadioButton.Checked property
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Radio Button Grouping?
« Reply #6 on: April 30, 2013, 03:12:07 pm »
Maybe I don't understand what you want to do.  If you want one group of RadioButtons to toggle so that only one can be checked, the default behavior is that if they are in the same "container", I.E. TGroupBox, they are linked.  If you have RadioButtons in another "container" only those will be linked.

If you are trying to have them work independently then you should consider TCheckBox.
Lazarus Trunk / fpc 2.6.2 / Win32

Ruptor

  • Full Member
  • ***
  • Posts: 201
Re:[Solved] Radio Button Grouping?
« Reply #7 on: April 30, 2013, 05:45:14 pm »
Hi Guys
    Thanks a lot for your help and patience. The reason I couldn't get the TRadioGroup to group the radio buttons was because I was doing things in the wrong order. I already had the radio buttons on the form and I thought if I dragged them on to the  new group box they would get linked but they don't. When I opened a new group box then added new radio buttons they work independently to the rest of the radio buttons on the form. Sorry I couldn't twig the problem sooner. Both TRadioGroup and TGroupBox methods work fine now that I set up the group box on the form first then add Radio buttons afterwards. I should have realised that when I dragged the existing radio buttons on to a new group box and they disappeared that something was wrong. I had to move the Z-order of the group box to see the radio buttons again but the radio buttons on the working group box don't disappear when placed on the box.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Radio Button Grouping?
« Reply #8 on: April 30, 2013, 05:51:17 pm »
If the radio buttons are already there and you want to put them as children of a group box, you can cut and paste. Ensure the radio buttons appear as a subnode of the group box in the object inspector treeview (you can also cut and paste here in this treeview).

Ruptor

  • Full Member
  • ***
  • Posts: 201
Re: Radio Button Grouping?
« Reply #9 on: April 30, 2013, 09:01:52 pm »
I think I will quit while I'm ahead because I tried cut & paste on the object tree list but it just moved the Radio buttons on the same level so they were still not linked only underneath the radio group lint the list. It sounded simple but I can't do it.  :-X

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Radio Button Grouping?
« Reply #10 on: April 30, 2013, 09:25:25 pm »
If you are using TRadioGroup, you don't need to add RadioButtons from the ToolBar.  Select the TRadioGroup on your Form and in the Property Editor select "Items".  Double-click where it says TStrings. That will bring up an editor.  Type the caption for each RadioButton on a separate line and close the editor.  That will create the RadioButtons for you and they are a part of the TRadioGroup, spaced to fit the area.  You can resize the TRadioGroup so that the spacing looks right.
Lazarus Trunk / fpc 2.6.2 / Win32

Ruptor

  • Full Member
  • ***
  • Posts: 201
Re: Radio Button Grouping?
« Reply #11 on: April 30, 2013, 10:23:17 pm »
Ok thanks. There seem to be a lot of ways to do the same thing. Amazing that I couldn't do it in the first place. :o

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Radio Button Grouping?
« Reply #12 on: May 01, 2013, 03:50:10 am »
Quote
I think I will quit while I'm ahead because I tried cut & paste on the object tree list but it just moved the Radio buttons on the same level so they were still not linked only underneath the radio group lint the list. It sounded simple but I can't do it. 
Click on the group box first before paste (similar in the object inspector treeview, click the group box node first)

 

TinyPortal © 2005-2018