Exemplo n.º 1
0
        internal string GetCSVText(bool skipFirstItem)
        {
            string ListText   = String.Empty;
            int    StartIndex =
                DropDownStyle == ComboBoxStyle.DropDownList &&
                DataSource == null &&
                skipFirstItem
                    ? 1
                    : 0;

            for (int Index = StartIndex; Index <= _CheckBoxComboBoxListControl.Items.Count - 1; Index++)
            {
                CheckBoxComboBoxItem Item = _CheckBoxComboBoxListControl.Items[Index];
                if (Item.Checked)
                {
                    ListText += string.IsNullOrEmpty(ListText) ? Item.Text : String.Format(", {0}", Item.Text);
                }
            }
            return(ListText);
        }
Exemplo n.º 2
0
        public void SynchroniseControlsWithComboBoxItems()
        {
            SuspendLayout();
            if (_CheckBoxComboBox._MustAddHiddenItem)
            {
                _CheckBoxComboBox.Items.Insert(
                    0, _CheckBoxComboBox.GetCSVText(false));
                _CheckBoxComboBox.SelectedIndex      = 0;
                _CheckBoxComboBox._MustAddHiddenItem = false;
            }
            Controls.Clear();

            for (int Index = _Items.Count - 1; Index >= 0; Index--)
            {
                CheckBoxComboBoxItem Item = _Items[Index];
                if (!_CheckBoxComboBox.Items.Contains(Item.ComboBoxItem))
                {
                    _Items.Remove(Item);
                    Item.Dispose();
                }
            }

            bool HasHiddenItem =
                _CheckBoxComboBox.DropDownStyle == ComboBoxStyle.DropDownList &&
                _CheckBoxComboBox.DataSource == null &&
                !DesignMode;

            CheckBoxComboBoxItemList NewList = new CheckBoxComboBoxItemList(_CheckBoxComboBox);

            for (int Index0 = 0; Index0 <= _CheckBoxComboBox.Items.Count - 1; Index0++)
            {
                object Object             = _CheckBoxComboBox.Items[Index0];
                CheckBoxComboBoxItem Item = null;

                if (Index0 == 0 && HasHiddenItem && _Items.Count > 0)
                {
                    Item = _Items[0];
                }
                else
                {
                    int StartIndex = HasHiddenItem ? 1 : 0;
                    for (int Index1 = StartIndex; Index1 <= _Items.Count - 1; Index1++)
                    {
                        if (_Items[Index1].ComboBoxItem == Object)
                        {
                            Item = _Items[Index1];
                            break;
                        }
                    }
                }
                if (Item == null)
                {
                    Item = new CheckBoxComboBoxItem(_CheckBoxComboBox, Object);
                    Item.ApplyProperties(_CheckBoxComboBox.CheckBoxProperties);
                }
                NewList.Add(Item);
                Item.Dock = DockStyle.Top;
            }
            _Items.Clear();
            _Items.AddRange(NewList);

            if (NewList.Count > 0)
            {
                NewList.Reverse();

                Controls.AddRange(NewList.ToArray());
            }

            if (_CheckBoxComboBox.DropDownStyle == ComboBoxStyle.DropDownList &&
                _CheckBoxComboBox.DataSource == null &&
                !DesignMode)
            {
                _CheckBoxComboBox.CheckBoxItems[0].Visible = false;
            }

            ResumeLayout();
        }