CheckListBoxCheckAll (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example demostrates the use of some Check box list methods. Example assumes you have a TCheckListBox and two buttons on the form.

Code

procedure TMainForm.btCheckAllClick(Sender: TObject);
begin
  { Check all the check boxes in the list.
    Do not change the state of the dimmed check box }
  CheckListBox.CheckAll(cbChecked, false, true);
end;

procedure TMainForm.btUncheckAllClick(Sender: TObject);
begin
  { Uncheck all the check boxes in the list.
    Do not touch the disabled check boxes. }
  CheckListBox.CheckAll(cbUnchecked, true, false);
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  { Add a few check boxes to the list. }
  CheckListBox.Items.Add('Option 1');
  CheckListBox.Items.Add('Option 2');
  CheckListBox.Items.Add('Option 3');
  CheckListBox.Items.Add('Option 4');

  { Allow the user to set the check boxes 
    into the dimmed state. }
  CheckListBox.AllowGrayed := true;

  { Make the first check box dimmed. }
  CheckListBox.State[0] := cbGrayed;

  { Make the second check box disabled. }
  CheckListBox.ItemEnabled[1] := false;
end;

Uses