Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Disable Specific Items in CheckedListBoxControl via Event

  • 2 minutes to read

The following example shows how to disable specific items in a checked list box control via the BaseCheckedListBoxControl.GetItemEnabled event.

Assume that a CheckedListBoxControl is bound to a BindingSource object containinig information on products. The data source contains a ProductName and Discontinued fields. The values of the ProductName field are displayed in the control. The values of the Discontinued field are used to decide whether a corresponding check item should be disabled.

The result is displayed below:

CheckedListBoxControl_GetItemEnabled

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

// Assign a data source to the checked list box.
checkedListBoxControl1.DataSource = productsBindingSource;
checkedListBoxControl1.DisplayMember = "ProductName";

// Disable the items that have the Discontinued field set to true
private void checkedListBoxControl1_GetItemEnabled(object sender, GetItemEnabledEventArgs e) {
    CheckedListBoxControl control = sender as CheckedListBoxControl;
    bool isDiscontinued = (bool)((control.DataSource as BindingSource)[e.Index] as 
        DataRowView)["Discontinued"];
    if (isDiscontinued)
        e.Enabled = false;
}