Using a Check ListBox Component

A further extension to the Phrases example is the use of the CheckListBox component, a component originally introduced by Borland in Delphi 3. This is basically a list box with a custom output (or an owner-draw list box, to use the proper technical term). Each item of the list is preceded by a check box. A user can select a single item of the list, but can also click on the check boxes to toggle their status.

If the component has the AllowGrayed property set to True, then each check box can be non-selected, grayed, or selected. Clicking on the check box alternates these three possible conditions. To check the current status of each item you can use the Checked and the State property. Both are array properties. The first, Checked, is a Boolean property you should use when AllowGrayed is set to False. The second, State, is a property of the TCheckBoxState data type:

I type

TCheckBoxState = (cbUnchecked, cbChecked, cbGrayed) This property should be used when AllowGrayed is set to True, to distinguish among the three different states of each item. Apart from these properties, the specific user interface, and the new OnClickCheck event, this component behaves as a ListBox.

Checklistbox Delphi Example

As I mentioned at the beginning of this section, to show you an example of the use of this component I've further updated the Phrases3 example, building the Phrases4 version. I've basically replaced the first multiple selection list box with the new CheckListBox component, set its Sorted property to True, and copied the Items. Then I've updated the code, replacing the ListBoxl object with the CheckListBoxl object, and replacing the Selected property of the first with the Checked property of the second in the ChangeText method. Here is an excerpt of the new version of this method:

| for ListItem := 0 to CheckListBoxl.Items.Count - l do

if CheckListBox1.Checked [ListItem] then begin

  • if the item is selected increase the count} Inc (SelectCount); if SelectCount = 1 then begin
  • store the string of the first selection} TmpStr1 := CheckListBox1.Items.Strings [ListItem]; TmpStr2 := TmpStr1; end else if SelectCount = 2 then he important point of this program is that this component makes it more obvious to the user that the list box allows multiple selections. The plain list box, in fact, gives no clue of this fact.

Was this article helpful?

+5 -2
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


  • Amelia
    How to gray out a checkedlistbox in delphi?
    9 years ago
  • burtuka senay
    How to use checklistbox in delphi?
    7 years ago
  • tesmi
    How to use a checklist box in delphi?
    3 years ago
  • shay
    How to code a checklistbox on delphi?
    8 months ago

Post a comment