Skip to main content

CheckedListBoxControl Class

The checked list box control, in which each item can be checked, unchecked or set to the grayed state. The control can be populated with items from a data source.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[CheckedListBoxControl.CheckedListBoxControlCustomBindingProperties]
public class CheckedListBoxControl :
    BaseCheckedListBoxControl,
    IBehaviorPropertiesFilter

The following members return CheckedListBoxControl objects:

Remarks

By default, the CheckedListBoxControl renders its items as text strings with built-in check boxes that reflect item check states.

CheckedListBoxControl class

The Item Templates feature helps you render each listbox item as your needs dictate. Each item can display multiple text and image elements arranged in any manner, and painted using different appearance settings. There are no built-in check boxes when listbox items are rendered from a template. Instead, item check states are indicated with check marks.

CheckedListBox-TemplatedItem

An end-user can switch between item check states by double-clicking or clicking an item with the mouse (see BaseCheckedListBoxControl.CheckOnClick) or by pressing the keyboard SPACE bar.

The control’s main members include:

Checked States vs. Selection vs. Hot-Tracking

Make note of the difference between an item’s checked, selected and hot-tracked states. An item’s checked state is visually indicated by the item’s check box. Item hot-tracking (disabled by default) is highlighting an item on a mouse hover. Once the mouse cursor leaves an item’s bounds, the item loses its hot-tracked state. Item selection is the capability to select (visually highlight) an item (or multiple items) and keep this highlighting after the mouse cursor leaves the control’s bounds.

The following image demonstrates a CheckedListBoxControl, in which the ‘Beijing’ item is checked, and the two items (‘Seoul’ and ‘Hong Kong’) are selected.

CheckedListBox-CheckedVsSelected.png

When one or more items are selected, you can toggle the check states of all selected items at once by pressing the SPACE key or clicking a check box of any selected item.

An end-user can select an item using the keyboard navigation keys, by clicking an item with the mouse, and optionally by hovering (hot-tracking) the item. Multiple item selection can be enabled with the BaseListBoxControl.SelectionMode property. See this topic to know how items can be selected by end-users in multi-selection modes.

The item hot-tracking feature is initially disabled, and can be enabled with the BaseListBoxControl.HotTrackItems property. The BaseListBoxControl.HotTrackSelectMode property allows you to specify whether an item is immediately selected once it is hot-tracked, or not. Item hot-tracking is not supported in multi-selection modes.

Note

A user needs to click an item twice to change its check state. The first click selects this item, and the second click toggles its check state. If you want to perform both actions on one click, set the CheckedListBoxControl.CheckOnClick property to true.

Item Checking API

The table below shows members related to the item checking functionality.

Properties Description
BaseCheckedListBoxControl.AllowGrayed Gets or sets whether check items in the checked list box should support three check states rather than two.
BaseCheckedListBoxControl.CheckedIndices Gets the collection of indexes corresponding to checked items.
BaseCheckedListBoxControl.CheckedItems Gets the collection of checked item values.
BaseCheckedListBoxControl.CheckedItemsCount Returns the number of checked items in the BaseCheckedListBoxControl.Items collection.
BaseCheckedListBoxControl.CheckMember Gets or sets the name of the data source field that provides check states for listbox items.
CheckedListBoxControl.CheckMode Gets or sets whether single or multiple items can be checked simultaneously.
BaseCheckedListBoxControl.CheckOnClick Gets or sets whether one or two mouse clicks are required to toggle the check state of an unfocused (unselected) item.
BaseCheckedListBoxControl.CheckStyle Gets or sets a value that determines the look and feel of the check boxes. This property is not supported when listbox items are rendered based on Item Templates
BaseCheckedListBoxControl.PictureChecked Gets or sets a custom image representing check boxes in the checked state. This property is in effect if the BaseCheckedListBoxControl.CheckStyle property is set to CheckStyles.UserDefined.
BaseCheckedListBoxControl.PictureGrayed Gets or sets a custom image representing check boxes in the intermediate state. This property is in effect if the BaseCheckedListBoxControl.CheckStyle property is set to CheckStyles.UserDefined.
BaseCheckedListBoxControl.PictureUnchecked Gets or sets a custom image representing check boxes in the unchecked state. This property is in effect if the BaseCheckedListBoxControl.CheckStyle property is set to CheckStyles.UserDefined.
CheckedListBoxItem.CheckState Gets or sets the item’s state.
Methods Description
BaseCheckedListBoxControl.CheckAll Checks all the items in the list box.
BaseCheckedListBoxControl.CheckSelectedItems Checks all selected (highlighted) items.
BaseCheckedListBoxControl.GetItemChecked Gets a value indicating whether the item is checked.
BaseCheckedListBoxControl.GetItemCheckState Gets the check state of the item specified by its index.
BaseCheckedListBoxControl.InvertCheckState Inverts the check state for each item in the BaseCheckedListBoxControl.Items collection.
BaseCheckedListBoxControl.IsAllSelectedItemsChecked Returns whether all selected (highlighted) items are checked.
BaseCheckedListBoxControl.SetItemChecked Sets the specified item’s state to checked or unchecked.
BaseCheckedListBoxControl.SetItemCheckState Sets the check state of the item.
BaseCheckedListBoxControl.UnCheckAll Unchecks all the items.
BaseCheckedListBoxControl.UnCheckSelectedItems Unchecks all selected (highlighted) items.
CheckedListBoxItem.InvertCheckState Inverts the item’s check state.
Events Description
BaseCheckedListBoxControl.CheckMemberChanged Occurs when the BaseCheckedListBoxControl.CheckMember property value is changed.
BaseCheckedListBoxControl.ConvertCheckValue Occurs when the field value is fetched from the data source and then posted back.
BaseCheckedListBoxControl.ItemCheck Fires after an item’s check state changes.
BaseCheckedListBoxControl.ItemChecking Fires before an item’s check state changes and allows you to cancel the action.

Item Selection API

The following members support the item selection feature:

Properties Description
BaseListBoxControl.HighlightedItemStyle Gets or sets the paint mode for the selected and hot-tracked items.
BaseListBoxControl.HotTrackSelectMode Gets or sets how items are selected when item hot-tracking is enabled.
BaseListBoxControl.SelectedIndex Gets or sets the index of the currently selected item.
BaseListBoxControl.SelectedIndices Gets a collection containing the indexes of all currently selected items in the list box control.
BaseListBoxControl.SelectedItem Gets or sets the currently selected item.
BaseListBoxControl.SelectedItems Gets currently selected items.
BaseListBoxControl.SelectedValue Gets or sets the currently selected item’s value.
BaseListBoxControl.SelectionMode Gets or sets whether a single or multiple items can be selected.
Methods Description
BaseCheckedListBoxControl.CheckSelectedItems Checks all selected (highlighted) items.
BaseCheckedListBoxControl.IsAllSelectedItemsChecked Returns whether all selected (highlighted) items are checked.
BaseListBoxControl.SetSelected Sets the specified item’s selection state.
BaseCheckedListBoxControl.ToggleSelectedItems Inverts the check states of selected items.
BaseCheckedListBoxControl.UnCheckSelectedItems Unchecks all selected (highlighted) items.
BaseListBoxControl.UnSelectAll Unselects all items when multiple item selection is enabled.
Events Description
BaseListBoxControl.SelectedIndexChanged Allows you to respond to item selection.
BaseListBoxControl.SelectedValueChanged Occurs after a value of the selected item has been changed.

Search and Filtering

You can allow users to filter CheckedListBoxControl contents in a separate SearchControl. For this purpose, set the SearchControl.Client property to the target CheckedListBoxControl.

searchControl1.Client = listBoxControl1;

When a user types a search request in the SearchControl, the bound CheckedListBoxControl automatically filters its items, and highlights the search text within the filtered items.

ListBoxControl_SearchHighlight

HTML-Inspired Formatting Specifics

If items are formatted using the HTML tags (see BaseListBoxControl.AllowHtmlDraw), the items are filtered, but not highlighted.

Check States of Items are Reset in Bound Mode

In bound mode, CheckedListBoxControl may clear the check states of its items when a SearchControl’s filter is changed. This happens if you do not specify the CheckMember property.

Workaround

Your data source should contain a Boolean field that stores the check states of items. Use the CheckMember property to assign this field to the CheckedListBoxControl.

Tooltips

DevExpress controls support regular and super tooltips. If the ShowToolTips option is enabled, tooltips are shown when the mouse pointer hovers over the control.

Use the following properties to specify a regular tooltip’s content:

  • ToolTip — A regular tooltip’s text. If the text is not specified, the tooltip is not displayed even if the title is specified. You can use line breaks in regular tooltips. Use the AllowHtmlTextInToolTip property to specify whether to parse HTML tags in the text. HTML tags allow you to format the text: size, style, hyperlinks, etc.
  • ToolTipTitle — A regular tooltip’s title. If the title is not specified, it is not displayed.
  • ToolTipIconType — A regular tooltip’s predefined icon. Use the controller’s IconSize property to specify the image size.

    image

    To display a custom image in all regular tooltips, use the controller’s ImageList and ImageIndex properties.

    To display a custom image in a specific regular tooltip, handle the BeforeShow event. Use the ImageOptions event argument to assign a raster or vector image to the processed tooltip.

Use the SuperTip property to assign a super tooltip to a control. Enable the AllowHtmlText property to use HTML tags in the super tooltip.

To replace regular tooltips with super tooltips, set the ToolTipController.ToolTipType property to SuperTip. The controller automatically converts regular tooltips to super tooltips. To access this property, you can use the DefaultToolTipController component or a custom controller assigned to the ToolTipController property. See the following topic for more information: Hints and Tooltips.

Example

The following sample code demonstrates how to create and populate a CheckedListBoxControl at runtime. The image below illustrates the control’s look & feel after sample code execution.

CheckedListBoxControl

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
// ...
CheckedListBoxItem[] items = {
                                 new CheckedListBoxItem("January", false),
                                 new CheckedListBoxItem("February", false),
                                 new CheckedListBoxItem("March", true),
                                 new CheckedListBoxItem("April", false),
                                 new CheckedListBoxItem("May", false),
                                 new CheckedListBoxItem("June", true),
                                 new CheckedListBoxItem("July", true),
                                 new CheckedListBoxItem("August", false),
                                 new CheckedListBoxItem("September", false),
                                 new CheckedListBoxItem("October", false),
                                 new CheckedListBoxItem("November", false),
                                 new CheckedListBoxItem("December", false)
                              };
private void CreateCheckedListBoxControl(CheckedListBoxItem[] items){
   CheckedListBoxControl checkedListBoxControl = new CheckedListBoxControl();
   Controls.Add(checkedListBoxControl);
   checkedListBoxControl.Left = 20;
   checkedListBoxControl.Top = 20;
   checkedListBoxControl.Width = 200;
   checkedListBoxControl.Height = 150;
   checkedListBoxControl.Items.AddRange(items);
}
// ...
CreateCheckedListBoxControl(items);
See Also