Difference between revisions of "TCheckListBox"
(Created page with "A '''TCheckListBox''' image:tchecklistbox.png is a component that shows a (scrollable) list of checkboxes where user can make multiple selections. It is available from the...") |
|||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TCheckListBox}} | ||
+ | |||
A '''TCheckListBox''' [[image:tchecklistbox.png]] is a component that shows a (scrollable) list of checkboxes where user can make multiple selections. It is available from the [[Additional tab]] of the [[Component Palette]]. | A '''TCheckListBox''' [[image:tchecklistbox.png]] is a component that shows a (scrollable) list of checkboxes where user can make multiple selections. It is available from the [[Additional tab]] of the [[Component Palette]]. | ||
+ | |||
+ | [[File:CheckListBoxDemo.png]] | ||
+ | |||
+ | == Usage == | ||
+ | |||
+ | Think of TCheckListBox as having two parts, the strings in a [[TListBox]] shown to the right and the checkboxes to the left. The strings are typically descriptions of what the user is selecting if they click a checkbox. The strings may be loaded individually using (eg) - | ||
+ | |||
+ | <syntaxhighlight lang="pascal">CheckListBox1.AddItem('Line One', Nil); | ||
+ | CheckListBox1.AddItem('Line Two', Nil);</syntaxhighlight> | ||
+ | |||
+ | Or you can assign an existing string list filled elsewhere - | ||
+ | |||
+ | <syntaxhighlight lang="pascal">CheckListBox1.Items.Assign(MyStringList);</syntaxhighlight> | ||
+ | |||
+ | Its a good idea to then put the checkboxes in a know state - | ||
+ | |||
+ | <syntaxhighlight lang="pascal"> for I := 0 to CheckListBox1.Count-1 do | ||
+ | CheckListBox1.Checked[I] := False;</syntaxhighlight> | ||
+ | |||
+ | TCheckListBox allows the user to select as many or as few checkboxes as they like. Use the OnItemClick event to force no more than one - | ||
+ | |||
+ | <syntaxhighlight lang="pascal">procedure TNoteBookPick.CheckListBox1ItemClick(Sender: TObject; Index: integer); | ||
+ | var | ||
+ | I : integer; | ||
+ | begin | ||
+ | if (Sender as TCheckListBox).Checked[Index] then begin | ||
+ | for I := 0 to CheckListBox1.Count -1 do | ||
+ | CheckListBox1.Checked[I] := False; | ||
+ | CheckListBox1.Checked[Index] := True; | ||
+ | end; | ||
+ | end;</syntaxhighlight> | ||
+ | |||
+ | To read the Check Boxes when (eg) the user has finished - | ||
+ | |||
+ | <syntaxhighlight lang="pascal"> for I := 0 to CheckListBox1.Count -1 do | ||
+ | if CheckListBox1.Checked[I] then DebugLn('Checked Item ' + CheckListBox1.Items[I]);</syntaxhighlight> | ||
+ | |||
+ | ==Comparison with TCheckGroup== | ||
+ | |||
+ | There is a similar control named TCheckGroup on Standard component pallette tab. The differences are | ||
+ | |||
+ | 1) The items within TCheckGroup are spaced evenly, while TCheckListBox allows scroll down. | ||
+ | |||
+ | 2) TCheckListBox has property of AllowGrayed. | ||
==See also== | ==See also== |
Latest revision as of 03:10, 4 April 2022
│
English (en) │
suomi (fi) │
français (fr) │
polski (pl) │
русский (ru) │
A TCheckListBox is a component that shows a (scrollable) list of checkboxes where user can make multiple selections. It is available from the Additional tab of the Component Palette.
Usage
Think of TCheckListBox as having two parts, the strings in a TListBox shown to the right and the checkboxes to the left. The strings are typically descriptions of what the user is selecting if they click a checkbox. The strings may be loaded individually using (eg) -
CheckListBox1.AddItem('Line One', Nil);
CheckListBox1.AddItem('Line Two', Nil);
Or you can assign an existing string list filled elsewhere -
CheckListBox1.Items.Assign(MyStringList);
Its a good idea to then put the checkboxes in a know state -
for I := 0 to CheckListBox1.Count-1 do
CheckListBox1.Checked[I] := False;
TCheckListBox allows the user to select as many or as few checkboxes as they like. Use the OnItemClick event to force no more than one -
procedure TNoteBookPick.CheckListBox1ItemClick(Sender: TObject; Index: integer);
var
I : integer;
begin
if (Sender as TCheckListBox).Checked[Index] then begin
for I := 0 to CheckListBox1.Count -1 do
CheckListBox1.Checked[I] := False;
CheckListBox1.Checked[Index] := True;
end;
end;
To read the Check Boxes when (eg) the user has finished -
for I := 0 to CheckListBox1.Count -1 do
if CheckListBox1.Checked[I] then DebugLn('Checked Item ' + CheckListBox1.Items[I]);
Comparison with TCheckGroup
There is a similar control named TCheckGroup on Standard component pallette tab. The differences are
1) The items within TCheckGroup are spaced evenly, while TCheckListBox allows scroll down.
2) TCheckListBox has property of AllowGrayed.
See also