Back to Devexpress

How to: Disable CheckedComboBoxEdit's Items via Event

windowsforms-9467-controls-and-libraries-editors-and-simple-controls-examples-how-to-disable-checkedcomboboxedits-items-via-event.md

latest1.6 KB
Original Source

How to: Disable CheckedComboBoxEdit's Items via Event

  • Oct 25, 2019

In the following example, it’s assumed that a CheckedComboBoxEdit control is bound to a data source containing a “Discontinued” field. The following code shows how to disable a CheckedComboBoxEdit control’s items, whose Discontinued fields are set to false. This is accomplished by handling the CheckedComboBoxEdit.GetItemEnabled event.

csharp
using DevExpress.XtraEditors;

private void checkedComboBoxEdit1_GetItemEnabled(object sender, 
    DevExpress.XtraEditors.Controls.GetCheckedComboBoxItemEnabledEventArgs e) {
    if (e.ListSourceRowIndex == -1) return;
    CheckedComboBoxEdit control = sender as CheckedComboBoxEdit;
    bool isDiscontinued = (bool)((control.Properties.DataSource as BindingSource)[e.ListSourceRowIndex] as DataRowView)["Discontinued"];
    e.Enabled = !isDiscontinued;
}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls

Private Sub CheckedComboBoxEdit1_GetItemEnabled(ByVal sender As System.Object,
    ByVal e As GetCheckedComboBoxItemEnabledEventArgs) Handles CheckedComboBoxEdit1.GetItemEnabled
    If e.ListSourceRowIndex = -1 Then Return
    Dim control As CheckedComboBoxEdit = TryCast(sender, CheckedComboBoxEdit)
    Dim isDiscontinued As Boolean = CBool((TryCast((TryCast(control.Properties.DataSource, BindingSource))(e.ListSourceRowIndex), DataRowView))("Discontinued"))
    e.Enabled = Not isDiscontinued
End Sub