Onions Have Layers
Onions Have Layers

Reputation: 39

Uncheck all checkboxes in a TCheckListBox

I want the user to be able to press a button to reset a TCheckListBox to it's initial state (having no boxes checked).

See images below of an example of what I want to happen after clicking the button:

Multiple checked boxes in a TCheckBoxList

Changed to:

No boxes are checked

How would I go about doing this? I know there would probably be a loop involved, but I'm unsure where to start. Thanks for the help in advance.

Upvotes: 1

Views: 1167

Answers (2)

MBo
MBo

Reputation: 80187

There is nice method - look at official help.

If we open TCheckListBox help page, choose Methods and filter off "inherited" ones, we'll see CheckAll method

CheckListBox1.CheckAll(cbUnchecked);

Upvotes: 8

MyICQ
MyICQ

Reputation: 1158

For individual checkboxes (missed this is a TCheckListBox).

Something along these lines,

Let's assume the checkboxes are on a panel called panel1.

var n: Integer;
begin
  for n := 0 to panel1.ComponentCount - 1 do 
     if panel1.Components[n] is TCheckbox then 
        Tcheckbox(panel1.components[n]).checked := False;
end; 

Note: if there is an event associated with the checkbox, you need to set the event to nil before modifying it, and returning the event after - else, the event will trigger as if you clicked the box.

Upvotes: 0

Related Questions