When I click on a checkbox inside the drop-down list, the control not only toggles the state of the checkbox, but it also changes the SelectedItem. I need to suppress the latter. SelectedItem should only change when I click outside of the checkbox.
Here's my best effort:
using System; using System.Windows.Forms; using Infragistics.Win; using Infragistics.Win.UltraWinEditors; namespace ComboTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); ((ICheckedItemList) ultraComboEditor1.Items.ValueList) .CheckStateChanged += OnCheckStateChanged; } private void OnCheckStateChanged( object sender, EditorCheckedListSettings.CheckStateChangedEventArgs checkStateChangedEventArgs ) { var priorSelectedItem = (ValueListItem) ((ValueList) sender).SelectedItem; if ( checkStateChangedEventArgs.Item != priorSelectedItem ) { _itemToRestore = priorSelectedItem; // unwanted change -> undo!
} } private void ultraComboEditor1_ValueChanged( object sender, EventArgs e ) { var editor = (UltraComboEditor) sender; if ( _itemToRestore != null && editor.SelectedItem != _itemToRestore ) { editor.SelectedItem = _itemToRestore; } _itemToRestore = null; } private ValueListItem _itemToRestore;
} }
Even though it's quite hackish, it used to work reasonably well in older versions of Infragistics, but in the current 13.2.20132.2016 the SelectedItem setter causes the drop-down to scroll the selected item to the top of the drop-down window, which is unacceptable.
Is there a better way to achieve the intended behavior, or is there at least a way to suppress or control the scrolling?
TIA!Hans
Hans,
Which version of Infragistics were you using before upgrading to 2013 volume 2?
Hi Michael
The version that we used before 2013.2 was 2011.2, but it was part of a more complex set-up, so now that I reconsider it, I'm not 100% positive that the demo app really would have worked.
The real app involved on-the-fly adding and removing the checkboxes (requiring recreating the HWND) as well as emptying and re-adding the items. After updating to 2013.2 we've seen issues where the drop-down would be only five or so pixels high, even though it contained items (they were selectable with the keyboard!).
What we do in the real application is this: the user has a regular drop-down listbox with a few items plus a "More..." item. Clicking the "More..." item drops down a much larger list with checkboxes, where the user can check/uncheck the ones that he wants to see in the short list and/or select an item from the long list. Clicking a checkbox must not change the selection though. We got this to work under 2011.2.
I have now redesigned the implementation to use two different comboboxes, one on top of the other, to avoid switching CheckedListSettings.CheckBoxStyle. I got this to work, except for this last flaw in the demo app.
Thank you for looking into it!Hans
P.S. We have occasionally seen the 5-px-only drop-down issue on other comboboxes, too. Those never have checkboxes, but we do empty and refill the items. We haven't been able to track this down yet, but we will have to. If we can fix that, then we might be able to revert to the old implementation.
Hello Hans,
Thank you for your response.
If you're adding items to the UltraComboEditor after it's already been dropped down, the dropdown will not resize to show the new items. You need to add the items before the UltraComboEditor has dropped down in order for it to take those items into account when sizing the dropdown.
Hello Dave,
Thank you for your reply.
I can see how this could be a problem, but not in this case. We had actually deferred the DropDown() call into an OnIdle handler to make sure that the UltraComboEditor had properly recovered from the changes and was ready. This used to work under 2011.2, but not anymore under 2013.2.
Hans
In order to proceed further with this issue, I will need a sample project which reproduces the issue. You can attach the zipped up project by selecting the Options tab when editing your post.
Please excuse the delay. I have not been able to isolate the 5px drop-down issue in a small sample project, but our requirements have changed in the meantime, so that we do not need a solution for this anymore.
However, we still need a solution for the selection issue that is demostrated in the sample project in the initial post: checking (or even unchecking!) a checkbox in the drop-down list selects that item. With a bit of hacking I've been able to preserve (or rather restore) the selection, but restoring the SelectedIndex programmatically scrolls the restored item to the top.
To see this, run the sample project, drop the list down, check item #10, scroll down further (using the mouse wheel) and check item #30. You'll see that the list scrolls item #10 to the top.
How can I suppress the scrolling, or alternatively, how can I retrieve and restore the scroll position, so that I can check and uncheck item #30 (and keep item #10 selected) without any scrolling?
Thanks!
It is currently not possible to do what you described. I recommend posting it on http://ideas.infragistics.com as a new Product Idea so our product management team knows about it.
Too bad, but thank you for your answer. I've posted
http://ideas.infragistics.com/forums/192359-windows-forms/suggestions/5943952-ultracomboeditor-in-checkbox-mode-allow-checking
and
http://ideas.infragistics.com/forums/192359-windows-forms/suggestions/5944101-provide-firstrow-firstindex-scrolltop-whatev
Best,Hans