Skip to main content

BaseCheckedListBoxControl.ItemCheck Event

Fires after an item’s check state changes.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

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 following example displays a message box after an item’s check state changes. The example prevents users from toggling the check state of the item with the specified name/description (“Item 0”).

Bound Mode

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System.ComponentModel;

namespace DXApplication {
    public partial class Form1 : XtraForm {
        BindingList<DataItem> items;
        public Form1() {
            InitializeComponent();
            items = new BindingList<DataItem>() {
                new DataItem(){ Name = "Item 0", Value = 0 },
                new DataItem(){ Name = "Item 1", Value = 1, Checked = true },
                new DataItem(){ Name = "Item 2", Value = 2 }
            };
            checkedListBoxControl1.DataSource = items;
            checkedListBoxControl1.DisplayMember = "Name";
            checkedListBoxControl1.ValueMember = "Value";
            checkedListBoxControl1.CheckMember = "Checked";
            checkedListBoxControl1.ItemChecking += CheckedListBoxControl1_ItemChecking;
            checkedListBoxControl1.ItemCheck += CheckedListBoxControl1_ItemCheck;
        }
        void CheckedListBoxControl1_ItemChecking(object sender, ItemCheckingEventArgs e) {
            CheckedListBoxControl list = (CheckedListBoxControl)sender;
            DataItem item = (DataItem)list.GetItem(e.Index);
            e.Cancel = item.Name == "Item 0";
        }
        //Display a message box after an item's check state changes.
        void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) {
            CheckedListBoxControl checkedListBox = (CheckedListBoxControl)sender;
            DataItem item = (DataItem)checkedListBox.GetItem(e.Index);
            XtraMessageBox.Show($"The check state of '{item.Name}' was changed. New state: {e.State}", "Information");
        }
    }
    public class DataItem {
        public string Name { get; set; }
        public int Value { get; set; }
        public bool Checked { get; set; }
    }
}

Unbound Mode

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System.Windows.Forms;

namespace DXApplication {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();
            checkedListBoxControl1.Items.AddRange(new CheckedListBoxItem[]{
                new CheckedListBoxItem(0, "Item 0"),
                new CheckedListBoxItem(1, "Item 1", CheckState.Checked),
                new CheckedListBoxItem(2, "Item 2"),
            });
            checkedListBoxControl1.ItemChecking += CheckedListBoxControl1_ItemChecking;
            checkedListBoxControl1.ItemCheck += CheckedListBoxControl1_ItemCheck;
        }
        void CheckedListBoxControl1_ItemChecking(object sender, ItemCheckingEventArgs e) {
            CheckedListBoxControl list = (CheckedListBoxControl)sender;
            CheckedListBoxItem item = (CheckedListBoxItem)list.GetItem(e.Index);
            e.Cancel = item.Description == "Item 0";
        }
        //Display a message box after an item's check state changes.
        void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) {
            CheckedListBoxControl checkedListBox = (CheckedListBoxControl)sender;
            CheckedListBoxItem item = (CheckedListBoxItem)checkedListBox.GetItem(e.Index);
            XtraMessageBox.Show($"The check state of '{item.Description}' was changed. New state: {e.State}", "Information");
        }
    }
}

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