Skip to main content
A newer version of this page is available. .

BaseCheckedListBoxControl.ItemCheck Event

Fires after an item’s check state changes.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v18.2.dll

Declaration

[DXCategory("Behavior")]
public event ItemCheckEventHandler ItemCheck

Event Data

The ItemCheck event's data class is ItemCheckEventArgs. The following properties provide information specific to this event:

Property Description
Index Gets the index of the item whose state was changed.
State Gets the state of the item.

Remarks

The ItemCheck event fires when an item’s CheckState property is changed by the user or in code. To get the new check state, read the State argument. The Index event argument returns the processed item’s index. If items in the list box are filtered (see SearchControl), this argument returns the item’s index in the filtered list.

The ItemChecking event fires before the check state changes. The event allows you to cancel the action.

Example

The code below shows a message when a list box item’s check state changes and prevents the first item from being checked.

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

for (int i = 0; i < 10; i++)
    checkedListBoxControl1.Items.Add(new CheckedListBoxItem(i, "Item " + i.ToString()));
checkedListBoxControl1.ItemChecking += CheckedListBoxControl1_ItemChecking;
checkedListBoxControl1.ItemCheck += checkedListBoxControl1_ItemCheck;

private void CheckedListBoxControl1_ItemChecking(object sender, ItemCheckingEventArgs e) {
    CheckedListBoxControl checkedListBox = (CheckedListBoxControl)sender;
    CheckedListBoxItem item = (CheckedListBoxItem)checkedListBox.GetItem(e.Index);
    if (item.Description == "Item 0") {
        MessageBox.Show($"You cannot change the {item.Description} item check state.");
        e.Cancel = true;
    }
}

private void checkedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) {
    CheckedListBoxControl checkedListBox = (CheckedListBoxControl)sender;
    CheckedListBoxItem item = (CheckedListBoxItem)checkedListBox.GetItem(e.Index);
    MessageBox.Show($"The {item.Description} item with the {item.Value} value is {item.CheckState}.");
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the ItemCheck event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also