Sign in Join
Wiki copytemporary

TCheckListBox: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11A **TCheckListBox** ![](/wiki-images/9/98/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]].
22
3-<figure>
4-<img src="CheckListBoxDemo.png" title="CheckListBoxDemo.png" />
5-<figcaption>CheckListBoxDemo.png</figcaption>
6-</figure>
3+![](/wiki-images/d/d6/CheckListBoxDemo.png)
74
85## Usage
96
107Think 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) -
118
129``` pascal
1310CheckListBox1.AddItem('Line One', Nil);
1411CheckListBox1.AddItem('Line Two', Nil);
1512```
1613
1714Or you can assign an existing string list filled elsewhere -
1815
1916``` pascal
2017CheckListBox1.Items.Assign(MyStringList);
2118```
2219
2320Its a good idea to then put the checkboxes in a know state -
2421
2522``` pascal
2623 for I := 0 to CheckListBox1.Count-1 do
2724 CheckListBox1.Checked[I] := False;
2825```
2926
3027TCheckListBox allows the user to select as many or as few checkboxes as they like. Use the OnItemClick event to force no more than one -
3128
3229``` pascal
3330procedure TNoteBookPick.CheckListBox1ItemClick(Sender: TObject; Index: integer);
3431var
3532 I : integer;
3633begin
3734 if (Sender as TCheckListBox).Checked[Index] then begin
3835 for I := 0 to CheckListBox1.Count -1 do
3936 CheckListBox1.Checked[I] := False;
4037 CheckListBox1.Checked[Index] := True;
4138 end;
4239end;
4340```
4441
4542To read the Check Boxes when (eg) the user has finished -
4643
4744``` pascal
4845 for I := 0 to CheckListBox1.Count -1 do
4946 if CheckListBox1.Checked[I] then DebugLn('Checked Item ' + CheckListBox1.Items[I]);
5047```
5148
5249## Comparison with TCheckGroup
5350
5451There is a similar control named TCheckGroup on Standard component pallette tab. The differences are
5552
56531\) The items within TCheckGroup are spaced evenly, while TCheckListBox allows scroll down.
5754
58552\) TCheckListBox has property of AllowGrayed.
5956
6057## See also
6158
6259- [[doc:lcl/checklst/tchecklistbox.html|TCheckListBox doc]]
6360- [[TCheckBox]]
6461- [[TListBox]]
6562
6663---
6764*From the Free Pascal wiki, page "TCheckListBox", as it stood on 2022-04-04 after a change by Egsuh, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history