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
505
UltraComboEditor: Setting checkboxes without changing the selection
posted

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

 

ComboTest.zip
Parents Reply Children
No Data