TCheckListBox: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TCheckListBox
| Old | New | Line | |
|---|---|---|---|
| 1 | + | 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]]. | |
| 2 | + | ||
| 3 | + | <figure> | |
| 4 | + | <img src="CheckListBoxDemo.png" title="CheckListBoxDemo.png" /> | |
| 5 | + | <figcaption>CheckListBoxDemo.png</figcaption> | |
| 6 | + | </figure> | |
| 7 | + | ||
| 8 | + | ## Usage | |
| 9 | + | ||
| 10 | + | 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) - | |
| 11 | + | ||
| 12 | + | ``` pascal | |
| 13 | + | CheckListBox1.AddItem('Line One', Nil); | |
| 14 | + | CheckListBox1.AddItem('Line Two', Nil); | |
| 15 | + | ``` | |
| 16 | + | ||
| 17 | + | Or you can assign an existing string list filled elsewhere - | |
| 18 | + | ||
| 19 | + | ``` pascal | |
| 20 | + | CheckListBox1.Items.Assign(MyStringList); | |
| 21 | + | ``` | |
| 22 | + | ||
| 23 | + | Its a good idea to then put the checkboxes in a know state - | |
| 24 | + | ||
| 25 | + | ``` pascal | |
| 26 | + | for I := 0 to CheckListBox1.Count-1 do | |
| 27 | + | CheckListBox1.Checked[I] := False; | |
| 28 | + | ``` | |
| 29 | + | ||
| 30 | + | 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 - | |
| 31 | + | ||
| 32 | + | ``` pascal | |
| 33 | + | procedure TNoteBookPick.CheckListBox1ItemClick(Sender: TObject; Index: integer); | |
| 34 | + | var | |
| 35 | + | I : integer; | |
| 36 | + | begin | |
| 37 | + | if (Sender as TCheckListBox).Checked[Index] then begin | |
| 38 | + | for I := 0 to CheckListBox1.Count -1 do | |
| 39 | + | CheckListBox1.Checked[I] := False; | |
| 40 | + | CheckListBox1.Checked[Index] := True; | |
| 41 | + | end; | |
| 42 | + | end; | |
| 43 | + | ``` | |
| 44 | + | ||
| 45 | + | To read the Check Boxes when (eg) the user has finished - | |
| 46 | + | ||
| 47 | + | ``` pascal | |
| 48 | + | for I := 0 to CheckListBox1.Count -1 do | |
| 49 | + | if CheckListBox1.Checked[I] then DebugLn('Checked Item ' + CheckListBox1.Items[I]); | |
| 50 | + | ``` | |
| 51 | + | ||
| 52 | + | ## Comparison with TCheckGroup | |
| 53 | + | ||
| 54 | + | There is a similar control named TCheckGroup on Standard component pallette tab. The differences are | |
| 55 | + | ||
| 56 | + | 1\) The items within TCheckGroup are spaced evenly, while TCheckListBox allows scroll down. | |
| 57 | + | ||
| 58 | + | 2\) TCheckListBox has property of AllowGrayed. | |
| 59 | + | ||
| 60 | + | ## See also | |
| 61 | + | ||
| 62 | + | - [[doc:lcl/checklst/tchecklistbox.html|TCheckListBox doc]] | |
| 63 | + | - [[TCheckBox]] | |
| 64 | + | - [[TListBox]] | |
| 65 | + | ||
| 66 | + | --- | |
| 67 | + | *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).* |
