Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
985
Check only one item in UltraComboEditor
posted

Is it possible to allow only one item in an UltraComboEditor  to be checked at any given time? I need to have a list of items in the combobox, but only one of them can be checked, so that you have either one or none items checked in the combobox.

How do I go about this?

Parents
No Data
Reply
  • 69832
    Verified Answer
    Offline posted

    This sort of defeats the purpose of using checkboxes for multiple selection, but it can be done by handling ICheckedItemList.CheckStateChanged and unchecking all other items, like so:

    ICheckedItemList list = this.ultraComboEditor.Items.ValueList as ICheckedItemList;
    list.CheckStateChanged += new EditorCheckedListSettings.CheckStateChangedHandler(list_CheckStateChanged);

    bool isInCheckStateChanged = false;
    void list_CheckStateChanged(object sender, EditorCheckedListSettings.CheckStateChangedEventArgs e)
    {
        ValueListItem checkedItem = e.Item as ValueListItem;
        if ( checkedItem == null || checkedItem.CheckState != CheckState.Checked )
            return;

        if ( this.isInCheckStateChanged )
            return;

        try
        {
            this.isInCheckStateChanged = false;

            ValueList vl = sender as ValueList;
            foreach( ValueListItem item in vl.ValueListItems )
            {
                if ( item == checkedItem )
                    continue;

                if ( item.CheckState == CheckState.Checked )
                   item.CheckState = CheckState.Unchecked;
            }
        }
        finally
        {
            this.isInCheckStateChanged = false;
        }
    }

Children