A newer version of this page is available. Switch to the current version.

BaseCheckedListBoxControl.ItemCheck Event

Fires after an item's check state changes.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v19.1.dll

Declaration

[DXCategory("Behavior")]
public event ItemCheckEventHandler ItemCheck
<DXCategory("Behavior")>
Public Event ItemCheck As ItemCheckEventHandler

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.

Examples

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}.");
}
See Also