Skip to main content
All docs
V24.2

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

BaseListBoxControl.Sort() Method

Raises the CustomSort event.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.2.dll

NuGet Package: DevExpress.Win.Navigation

#Declaration

public void Sort()

#Remarks

Handle the CustomSort event to sort list items in custom order. For optimization purposes, the editor itself does not raise the CustomSort event. Use the Sort method to raise the CustomSort event when needed.

#Example

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

using DevExpress.XtraEditors.Controls;

private void checkedListBoxControl1_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 checkedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) {
    checkedListBoxControl1.Sort();
}

private void Form1_Load(object sender, EventArgs e) {
    checkedListBoxControl1.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" },
    });

    checkedListBoxControl1.CheckOnClick = true;
}
See Also