Skip to main content
All docs
V25.2
  • CheckedComboBoxEdit.CustomSort Event

    Fires when items in the drop-down list need to be sorted in custom order.

    Namespace: DevExpress.XtraEditors

    Assembly: DevExpress.XtraEditors.v25.2.dll

    NuGet Package: DevExpress.Win.Navigation

    Declaration

    [DXCategory("Events")]
    public event EventHandler<CheckedListBoxCustomSortEventArgs> CustomSort

    Event Data

    The CustomSort event's data class is DevExpress.XtraEditors.Controls.CheckedListBoxCustomSortEventArgs.

    Remarks

    Handle the CustomSort event to compare two neighboring items (e.Item1 and e.Item2). You can compare items by their values (e.Value1, e.Value2) or display text (e.DisplayText1, e.DisplayText2). Set the e.Result event parameter to 1 to position the first item above the second item, or set it to -1 to position the second item above the first item.

    For optimization purposes, the editor itself does not raise the CustomSort event. Use the Sort() method to raise the CustomSort event when needed. For example, you can call this method within the ItemCheck event handler.

    Note

    Example

    The following code snippet sorts checked items first, followed by unchecked items.

    using System.Windows.Forms;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            checkedComboBoxEdit1.CustomSort += checkedComboBoxEdit1_CustomSort;
            checkedComboBoxEdit1.ItemCheck += checkedComboBoxEdit1_ItemCheck;
            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" },
            });
        }
    
        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;
        }
    
        void checkedComboBoxEdit1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) {
            checkedComboBoxEdit1.Sort();
        }
    }
    
    See Also