Example #1
0
        // Checks/Unchecks items depending on the give bitvalue
        protected void UpdateCheckedItems(ulong value)
        {
            isUpdatingCheckStates = true;

            // Iterate over all items
            for (int i = 0; i < Items.Count; i++)
            {
                FlagCheckedListBoxItem item = Items[i] as FlagCheckedListBoxItem;

                if (item.value == 0)
                {
                    SetItemChecked(i, value == 0);
                }
                else
                {
                    // If the bit for the current item is on in the bitvalue, check it
                    if ((item.value & value) == item.value && item.value != 0)
                    {
                        SetItemChecked(i, true);
                    }
                    // Otherwise uncheck it
                    else
                    {
                        SetItemChecked(i, false);
                    }
                }
            }

            isUpdatingCheckStates = false;
        }
Example #2
0
        public FlagCheckedListBoxItem Add(int v, string c)
        {
            var item = new FlagCheckedListBoxItem(v, c);

            Items.Add(item);
            return(item);
        }
Example #3
0
        // Adds an integer value and its associated description
        public FlagCheckedListBoxItem Add(ulong v, string c)
        {
            FlagCheckedListBoxItem item = new FlagCheckedListBoxItem(v, c);

            Items.Add(item);
            return(item);
        }
Example #4
0
        protected override void OnItemCheck(ItemCheckEventArgs e)
        {
            base.OnItemCheck(e);

            if (isUpdatingCheckStates)
            {
                return;
            }

            // Get the checked/unchecked item
            FlagCheckedListBoxItem item = Items[e.Index] as FlagCheckedListBoxItem;

            // Update other items
            UpdateCheckedItems(item, e.NewValue);
        }
Example #5
0
        // Gets the current bit value corresponding to all checked items
        public ulong GetCurrentValue()
        {
            ulong sum = 0;

            for (int i = 0; i < Items.Count; i++)
            {
                FlagCheckedListBoxItem item = Items[i] as FlagCheckedListBoxItem;

                if (GetItemChecked(i))
                {
                    sum |= item.value;
                }
            }

            return(sum);
        }
Example #6
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)
            {
                UpdateCheckedItems(0);
            }


            // Get the total value of all checked items
            ulong sum = 0;

            for (int i = 0; i < Items.Count; i++)
            {
                FlagCheckedListBoxItem 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
            UpdateCheckedItems(sum);
        }
Example #7
0
 public FlagCheckedListBoxItem Add(FlagCheckedListBoxItem item)
 {
     Items.Add(item);
     return(item);
 }
Example #8
0
 // Returns true if this value is a member of the composite bit value
 public bool IsMemberFlag(FlagCheckedListBoxItem composite)
 {
     return(IsFlag && ((value & composite.value) == value));
 }
Example #9
0
 public FlagCheckedListBoxItem Add(FlagCheckedListBoxItem item)
 {
     Items.Add(item);
     return item;
 }
Example #10
0
 // Adds an integer value and its associated description
 public FlagCheckedListBoxItem Add(int v,string c)
 {
     FlagCheckedListBoxItem item = new FlagCheckedListBoxItem(v,c);
     Items.Add(item);
     return item;
 }
Example #11
0
 // Returns true if this value is a member of the composite bit value
 public bool IsMemberFlag(FlagCheckedListBoxItem composite)
 {
     return (IsFlag && ((value & composite.value) == value));
 }
Example #12
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)
                UpdateCheckedItems(0);

            // Get the total value of all checked items
            int sum = 0;
            for(int i=0;i<Items.Count;i++)
            {
                FlagCheckedListBoxItem 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
            UpdateCheckedItems(sum);
        }