Пример #1
0
 public FlagCheckedListBoxItem Add(FlagCheckedListBoxItem item)
 {
     Items.Add(item);
     return item;
 }
Пример #2
0
 // Returns true if this value is a member of the composite bit value
 public bool IsMemberFlag(FlagCheckedListBoxItem composite)
 {
     return (this.IsFlag && ((this.value & composite.value) == this.value));
 }
Пример #3
0
 // Adds an integer value and its associated description
 public FlagCheckedListBoxItem Add(int v, string c)
 {
     var item = new FlagCheckedListBoxItem(v, c);
     Items.Add(item);
     return item;
 }
Пример #4
0
        // Updates items in the checklistbox
        // composite = The item that was checked/unchecked
        // cs = The check state of that item
        protected void UpdateCheckedItems(FlagCheckedListBoxItem composite, CheckState cs)
        {
            // If the value of the item is 0, call directly.
            if (composite.value == 0)
                this.UpdateCheckedItems(0);

            // Get the total value of all checked items
            int sum = 0;
            for (int i = 0; i < Items.Count; i++)
            {
                var item = Items[i] as FlagCheckedListBoxItem;

                // If item is checked, add its value to the sum.
                if (GetItemChecked(i))
                    sum |= item.value;
            }

            // If the item has been unchecked, remove its bits from the sum
            if (cs == CheckState.Unchecked)
                sum = sum & (~composite.value);
            // If the item has been checked, combine its bits with the sum
            else
                sum |= composite.value;

            // Update all items in the checklistbox based on the final bit value
            this.UpdateCheckedItems(sum);
        }