Skip to main content

TcxCustomCheckListBox.AllowGrayed Property

Enables list box items to be in one of three states (enabled, disabled and grayed).

Declaration

property AllowGrayed: Boolean read; write; default False;

Property Value

Type Default
Boolean False

Remarks

The AllowGrayed property enables a user to set items into a grayed state. If AllowGrayed is set to False, items can only be checked or unchecked. If AllowGrayed is True, items can also be grayed (i.e. an indeterminate state).

Note

To provide support for grayed items in an editor, set its EditValueFormat property to a value other than a cvfInteger value.

An end-user can switch state by clicking the item’s check box or by pressing the spacebar when the item is focused.

The following images display list boxes with the first four items in grayed state. Screenshots were made using XP and classic Windows® schemes:

To get the state of a specific item, see its State property.

Suppose you have a catalog of documents and you want to revise them by deleting outdated and unnecessary documents. A check list box control displays all available documents. A user can check items and then click, say a Delete button, in order to delete the corresponding documents. Unchecked items will not be affected. If items are set to the grayed state, a dialog will appear to confirm the delete operation.

The code to delete the selected documents can be implemented as follows:

procedure TForm1.ButtonDeleteClick(Sender: TObject);
var
  I: Integer;
  ADelete: Boolean;
begin
  for I := Pred(cxCheckListBox1.Items.Count) downto 0 do
  begin
    ADelete := False;
    case cxCheckListBox1.State[I] of
      cbsUnchecked: ;
      cbsChecked: ADelete := True;
      cbsGrayed:
        if MessageDlg('Delete ' + cxCheckListBox1.Items[I] + '?',
        mtConfirmation, [mbYes, mbNo], 0) = mrYes then
          ADelete := True;
    end;
   if ADelete then
   begin
     cxCheckListBox1.Items.Delete(I);
     {some actions}
   end;
  end;
end;

The default value of the AllowGrayed property is False.

See Also