TcxCustomCheckComboBoxProperties.OnClickCheck Event
Occurs when a user is about to change an item’s state.
Declaration
property OnClickCheck: TcxCheckComboClickCheckEvent read; write;
Remarks
Handle this event to control whether an item changes its state when a user clicks the item or presses the Space key while the item is focused.
The Sender parameter specifies the check combo box control that raised the event.
The item is passed as the ItemIndex parameter.
The AllowToggle parameter specifies whether the item’s state changes. Pass False as this parameter to prohibit the state change.
Suppose you are releasing two versions of a program: one is a fully functional version for registered users and the other one is a demo version. Your IsFullyFunctionalVersion function returns whether the program is fully functional or just a demo. A check combo box control enables you to select components (Sources, Documentation, Demo programs) to include into the release package.
The demo version cannot include the Sources component. So this item’s state is set to unchecked when building the demo package. The demo version must always contain demo programs. So the Demo item is checked.
In order to prevent toggling states of the Demo and Sources items, we handle the OnClickCheck event and set the AllowToggle parameter to False for these items. The state of the Documentation item can be freely changed at runtime.
//Declare indexes for check combo box items
var
FSourcesItemIndex, FDocItemIndex, FDemoItemIndex: Integer;
//...
//Populate the check combo box with three items and store their indexes
with cxCheckComboBox1.Properties.Items do
begin
Clear;
FSourcesItemIndex := AddCheckItem('Sources').Index;
FDocItemIndex := AddCheckItem('Documentation').Index;
FDemoItemIndex := AddCheckItem('Demos').Index;
end;
if not IsFullyFunctionalVersion then
begin
cxCheckComboBox1.SetItemState(FSourcesItemIndex, cbsUnchecked);
cxCheckComboBox1.SetItemState(FDocItemIndex, cbsUnchecked);
cxCheckComboBox1.SetItemState(FDemoItemIndex, cbsChecked);
end;
procedure TForm1.cxCheckComboBox1ClickCheck(Sender: TObject; ItemIndex: Integer; var AllowToggle: Boolean);
begin
if not IsFullyFunctionalVersion then
begin
if (ItemIndex = FSourcesItemIndex) or (ItemIndex = FDemoItemIndex)
then AllowToggle := False;
end;
end;