Back to Devexpress

CheckedComboBoxEdit.ItemCheck Event

windowsforms-devexpress-dot-xtraeditors-dot-checkedcomboboxedit-f942dfaa.md

latest4.6 KB
Original Source

CheckedComboBoxEdit.ItemCheck Event

Fires after an item’s check state was changed.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event EventHandler<ItemCheckEventArgs> ItemCheck
vb
<DXCategory("Events")>
Public Event ItemCheck As EventHandler(Of ItemCheckEventArgs)

Event Data

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

PropertyDescription
IndexGets the index of the item whose state was changed.
StateGets the state of the item.

Remarks

The ItemCheck event fires when an item’s CheckState property is changed by the user or in code. Use the State parameter to get the new check state. The Index event parameter gets the item’s index.

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

Example

This example demonstrates how to handle the CustomSort event to sort the checked items first and then the rest of the items.

csharp
using DevExpress.XtraEditors.Controls;

private void checkedComboBoxEdit1_CustomSort(object sender, CheckedListBoxCustomSortEventArgs e) {
    if(e.Item1.CheckState == e.Item2.CheckState)
        e.Result = ((string)e.Value1).CompareTo((string)e.Value2);
    else
        e.Result = e.Item1.CheckState == CheckState.Checked ? -1 : 1;
}
private void checkedComboBoxEdit1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) {
    checkedComboBoxEdit1.Sort();
}
private void Form1_Load(object sender, EventArgs e) {
    checkedComboBoxEdit1.Properties.Items.AddRange(
      new CheckedListBoxItem[] {
        new CheckedListBoxItem(){ Value = "Bart Arnaz" },
        new CheckedListBoxItem(){ Value = "Leah Simpson" },
        new CheckedListBoxItem(){ Value = "Arnie Schwartz" },
        new CheckedListBoxItem(){ Value = "Billy Zimmer" },
        new CheckedListBoxItem(){ Value = "Samantha Piper" },
        new CheckedListBoxItem(){ Value = "Maggie Boxter" },
        new CheckedListBoxItem(){ Value = "Brad Farkus" },
    });
}
vb
Imports DevExpress.XtraEditors.Controls

Private Sub checkedComboBoxEdit1_CustomSort(ByVal sender As Object, ByVal e As CheckedListBoxCustomSortEventArgs)
    If e.Item1.CheckState = e.Item2.CheckState Then
        e.Result = CStr(e.Value1).CompareTo(CStr(e.Value2))
    Else
        e.Result = If(e.Item1.CheckState = CheckState.Checked, -1, 1)
    End If
End Sub
Private Sub checkedComboBoxEdit1_ItemCheck(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ItemCheckEventArgs)
    checkedComboBoxEdit1.Sort()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    checkedComboBoxEdit1.Properties.Items.AddRange(New CheckedListBoxItem() {
        New CheckedListBoxItem() With {.Value = "Bart Arnaz"},
        New CheckedListBoxItem() With {.Value = "Leah Simpson"},
        New CheckedListBoxItem() With {.Value = "Arnie Schwartz"},
        New CheckedListBoxItem() With {.Value = "Billy Zimmer"},
        New CheckedListBoxItem() With {.Value = "Samantha Piper"},
        New CheckedListBoxItem() With {.Value = "Maggie Boxter"},
        New CheckedListBoxItem() With {.Value = "Brad Farkus"}
    })
End Sub

See Also

ItemChecking

CheckedComboBoxEdit Class

CheckedComboBoxEdit Members

DevExpress.XtraEditors Namespace