Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: checkbox count on panel?



Permlink Replies: 3 - Last Post: Oct 23, 2017 9:46 AM Last Post By: Remy Lebeau (Te...
Lawson Lutchman

Posts: 31
Registered: 8/12/05
checkbox count on panel?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2017 7:42 PM
Hello forum,

I have several checkboxes on a panel and for various design reasons cannot use a checkboxlist or group. How can I without writing a combination of AND or OR statements ensure (will throw an error/message) that no more than 2 check boxes are selected.

Thanks and regards,
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: checkbox count on panel?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2017 11:12 PM   in response to: Lawson Lutchman in response to: Lawson Lutchman
Lawson Lutchman wrote:

Hello forum,

I have several checkboxes on a panel and for various design reasons
cannot use a checkboxlist or group. How can I without writing a
combination of AND or OR statements ensure (will throw an
error/message) that no more than 2 check boxes are selected.

Thanks and regards,

You cannot, what you're looking for is the TRadioButton or TRadioGroup
component. The help can be very helpfull:

TRadioButton is a wrapper for a system radio button. 
 
Use TRadioButton to add a radio button to a form. Radio buttons present
a set of mutually exclusive options to the user- that is, only one
radio button in a set can be selected at a time. When the user selects
a radio button, the previously selected radio button becomes
unselected. Radio buttons are frequently grouped in a radio group box
(TGroupBox). Add the group box to the form first, then get the radio
buttons from the Component palette and put them into the group box. Or
you can add a TRadioGroup, a group that already has radio buttons in
it, so that you do not have to get the buttons from the Tool Palette.
 
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.

{code]
TRadioGroup represents a group of radio buttons that function together.

A TRadioGroup object is a special group box that contains only radio
buttons. Radio buttons that are placed directly in the same control
component are said to be "grouped." When the user checks a radio
button, all other radio buttons in its group become unchecked. Hence,
two radio buttons on a form can be checked at the same time only if
they are placed in separate containers, such as group boxes.

To add radio buttons to a TRadioGroup, edit the Items property in the
Object Inspector. Each string in Items makes a radio button appear in
the group box with the string as its caption. The value of the
ItemIndex property determines which radio button is currently selected.

Display the radio buttons in a single column or in multiple columns by
setting the Columns property.
{code}

PS. For questions about using components you should post into
Embarcadero.Public.Delphi.Vcl.Components.Using.

Lawson Lutchman

Posts: 31
Registered: 8/12/05
Re: checkbox count on panel?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2017 11:45 PM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Thanks!

Lajos Juhasz wrote:
Lawson Lutchman wrote:

Hello forum,

I have several checkboxes on a panel and for various design reasons
cannot use a checkboxlist or group. How can I without writing a
combination of AND or OR statements ensure (will throw an
error/message) that no more than 2 check boxes are selected.

Thanks and regards,

You cannot, what you're looking for is the TRadioButton or TRadioGroup
component. The help can be very helpfull:

TRadioButton is a wrapper for a system radio button. 
 
Use TRadioButton to add a radio button to a form. Radio buttons present
a set of mutually exclusive options to the user- that is, only one
radio button in a set can be selected at a time. When the user selects
a radio button, the previously selected radio button becomes
unselected. Radio buttons are frequently grouped in a radio group box
(TGroupBox). Add the group box to the form first, then get the radio
buttons from the Component palette and put them into the group box. Or
you can add a TRadioGroup, a group that already has radio buttons in
it, so that you do not have to get the buttons from the Tool Palette.
 
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.

{code]
TRadioGroup represents a group of radio buttons that function together.

A TRadioGroup object is a special group box that contains only radio
buttons. Radio buttons that are placed directly in the same control
component are said to be "grouped." When the user checks a radio
button, all other radio buttons in its group become unchecked. Hence,
two radio buttons on a form can be checked at the same time only if
they are placed in separate containers, such as group boxes.

To add radio buttons to a TRadioGroup, edit the Items property in the
Object Inspector. Each string in Items makes a radio button appear in
the group box with the string as its caption. The value of the
ItemIndex property determines which radio button is currently selected.

Display the radio buttons in a single column or in multiple columns by
setting the Columns property.
{code}

PS. For questions about using components you should post into
Embarcadero.Public.Delphi.Vcl.Components.Using.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: checkbox count on panel?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2017 9:46 AM   in response to: Lawson Lutchman in response to: Lawson Lutchman
Lawson Lutchman wrote:

How can I without writing a combination of AND or OR statements ensure
(will throw an error/message) that no more than 2 check boxes are
selected.

You would have to manually loop through the Panel's CheckBoxes counting
the ones that are checked, and then act accordingly.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02