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?
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; }}
I know that allowing only one item to be selected defeats the purpose of the checkboxes for multiple selection. However, in my case I use to checkboxes in the combobox to flag one item as being a special one, but it does not necessarily the item that is currently selected. I need to do this with a combobox like control due to the way my GUI is working, so using the UltraComboEditor seemed to be the best way to do it.
If you have suggestions for another control that might be able to achieve what I want then I am open to suggestions.
You could also highlight the "special" option using an appearance - giving it a different BackColor/ForeColor and/or making the font bold or something like that. :)
You could have considered using the UltraGrid within a UltraComboEditor and then you could use RadioButtons within the UltraGrid. I know I'm a few weeks late here with a response, but because the CheckBox is intended for multi-selection this may be worth considering?