Пример #1
0
        private void checkedComboBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (_stopEvent)
            {
                return;
            }

            var result = BaseIndex.SpecialFunction;

            if (e.Index == 0)
            {
                if (e.NewValue == CheckState.Unchecked)
                {
                    //не даем снять галку с первого
                    e.NewValue = CheckState.Checked;
                    return;
                }

                if (e.NewValue == CheckState.Checked)
                {
                    //снимаем все галки кроме первой
                    _stopEvent = true;
                    for (var i = 1; i < _specialFunctions.Count; i++)
                    {
                        SpecialFunctionCheckedComboBox.SetItemChecked(i, false);
                    }
                    _stopEvent = false;

                    result = SpecialFunction.NotSelected;
                }
            }
            else if (e.NewValue == CheckState.Checked)
            {
                //снимаем галку с первого если выделили новое
                _stopEvent = true;
                SpecialFunctionCheckedComboBox.SetItemChecked(0, false);
                _stopEvent = false;

                result = EnumHelper.RemoveFlag(result, SpecialFunction.NotSelected);
                result = result | _specialFunctions[e.Index];
            }
            else if (e.NewValue == CheckState.Unchecked)
            {
                result = EnumHelper.RemoveFlag(result, _specialFunctions[e.Index]);
                if (result == SpecialFunction.None)
                {
                    //сняли галки со всех, значит ничего не выбрано
                    _stopEvent = true;
                    SpecialFunctionCheckedComboBox.SetItemChecked(0, true);
                    _stopEvent = false;
                    result     = SpecialFunction.NotSelected;
                }
            }

            BaseIndex.SpecialFunction = result;
        }
Пример #2
0
        protected void CheckItems()
        {
            var i  = 0;
            var sf = BaseIndex.SpecialFunction;

            _stopEvent = true;
            foreach (var f in _specialFunctions)
            {
                SpecialFunctionCheckedComboBox.SetItemChecked(i, sf.HasFlag(f));
                i++;
            }
            _stopEvent = false;
        }