3009:How to check a ComboBox without OnClick ocurring.
KEYWORDS: checkbox onclick checked BM_SETCHECK AREA: VCL Programming
When you modify the state of a TCheckBox by setting the value
of its Checked property, the OnClick event of that TCheckBox
is fired. For example, the following code:
CheckBox1.Checked := True;
causes CheckBox1.OnClick to execute.
Sometimes, however, you may want to check or uncheck the
CheckBox in code without firing the OnClick event. You
can do this by sending a BM_SETCHECK message to the
ComboBox. The WParam of this message can be 1 (meaning
the box should be checked), or 0 (meaning the box should
be unchecked). The LParam of this message is always 0.
With this in mind, the following procedure accepts as
parameters a TCheckBox called CB and a Boolean parameter
called CheckIt. When CheckIt is True, the box will be
checked, and when it's False, the box will be unchecked:
procedure CheckNoClick(CB: TCheckBox; CheckIt: Boolean);
begin
CB.Perform(BM_SETCHECK, Ord(CheckIt), 0);
end;
Using this procedure, the code for checking a TComboBox
called ComboBox1 looks like this:
CheckNoClick(ComboBox1, True);
TI