Skip to main content

TcxCustomCheckListBox.OnClickCheck Event

Occurs when the end-user toggles the state of a specific item.

Declaration

property OnClickCheck: TcxClickCheckEvent read; write;

Remarks

The OnClickCheck event provides notification when an item’s state has changed. The item clicked is identified by the AIndex parameter and this specifies the item’s zero-based index within the collection of items (see the Items property). The new and old states are specified by the ANewState and APrevState parameters. Sender specifies the checklist box control itself.

Consider a check list box displaying four items corresponding to different font styles (bold, italic, underline and strikeout). The end-user is able to check/uncheck items and thus control the font settings of a label displaying a sample string.

In the OnClickCheck event handler, call the custom ChangeFont procedure with parameters identifying the font attribute and its state.

//Create items and store their indexes to identify the clicked items
//in an OnClickCheck event handler
var
  FBoldIndex, FItalicIndex, FUnderlineIndex, FStrikeOutIndex: Integer;
//...
  with cxCheckListBox1.Items do
  begin
    with Add do
    begin
      Text := 'Bold';
      FBoldIndex := Index;
    end;
    with Add do
    begin
      Text := 'Italic';
      FItalicIndex := Index;
    end;
    with Add do
    begin
      Text := 'Underline';
      FUnderlineIndex := Index;
    end;
    with Add do
    begin
      Text := 'StrikeOut';
      FStrikeOutIndex := Index;
    end;
  end;
//The OnClickCheck event handler
procedure TForm1.cxCheckListBox1ClickCheck(Sender: TObject; AIndex: Integer; APrevState, ANewState: TcxCheckBoxState);
begin
  if AIndex = FBoldIndex then
    ChangeFont([fsBold], ANewState = cbsChecked)
  else
  if AIndex = FItalicIndex then
    ChangeFont([fsItalic], ANewState = cbsChecked)
  else
  if AIndex = FUnderlineIndex then
    ChangeFont([fsUnderline], ANewState = cbsChecked)
  else
  if AIndex = FStrikeOutIndex then
    ChangeFont([fsStrikeOut], ANewState = cbsChecked)
end;
//Apply font changes to a label
procedure TForm1.ChangeFont(AFontChange: TFontStyles; AChecked: Boolean);
var
  AFont: TFont;
begin
  AFont := Label1.Font;
  if AChecked then
    AFont.Style := AFont.Style + AFontChange
  else
    AFont.Style := AFont.Style - AFontChange
end;

The following image shows a check list box with the Bold and Underline items checked.

The label, to which these font settings are applied has the following look:

See Also