Example #1
0
        /// <summary>
        /// Checks or unchecks items depending on the given bit value.
        /// </summary>
        /// <param name="value">The bit value.</param>
        private void UpdateCheckedItems(int value)
        {
            this.isUpdatingCheckStates = true;

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

                if (item == null)
                {
                    continue;
                }

                if (item.Value == 0)
                {
                    SetItemChecked(i, value == 0);
                }
                else
                {
                    SetItemChecked(i, (item.Value & value) == item.Value && item.Value != 0);
                }
            }

            this.isUpdatingCheckStates = false;
        }
Example #2
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 #3
0
        /// <summary>
        /// Updates items in the checklistbox.
        /// </summary>
        /// <param name="composite">The item that was checked/unchecked.</param>
        /// <param name="cs">The check state of that item.</param>
        private void UpdateCheckedItems(FlagCheckedListBoxItem composite, CheckState cs)
        {
            if (composite == null)
            {
                return;
            }

            // 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 = (from object t in this.Items select t as FlagCheckedListBoxItem)
                      .Where((item, i) => item != null && this.GetItemChecked(i))
                      .Aggregate(0, (current, item) => current | item.Value);

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

            // Update all items in the checklistbox based on the final bit value
            this.UpdateCheckedItems(sum);
        }
Example #4
0
            // Checks/Unchecks items depending on the give bitvalue
            protected void UpdateCheckedItems(int 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;
            }
            /// <summary>
            /// Adds an integer value to the listbox.
            /// </summary>
            /// <param name="p_intValue">The value to add to the list.</param>
            /// <param name="p_strDisplayName">The display name of the value to add.</param>
            /// <returns>The newly added <see cref="FlagCheckedListBoxItem"/> that represents the given value.</returns>
            private FlagCheckedListBoxItem Add(Int32 p_intValue, string p_strDisplayName)
            {
                FlagCheckedListBoxItem lbiEnumItem = new FlagCheckedListBoxItem(p_intValue, p_strDisplayName);

                Items.Add(lbiEnumItem);
                return(lbiEnumItem);
            }
            /// <summary>
            /// Gets the value currently represented by the selected list items.
            /// </summary>
            /// <returns>The value currently represented by the selected list items.</returns>
            public Int32 GetCurrentValue()
            {
                Int32 intValue = 0;

                for (Int32 i = 0; i < Items.Count; i++)
                {
                    FlagCheckedListBoxItem lbiItem = (FlagCheckedListBoxItem)Items[i];
                    if (GetItemChecked(i))
                    {
                        intValue |= lbiItem.Value;
                    }
                }
                return(intValue);
            }
Example #7
0
        /// <summary>
        /// Handles the raising of the <see cref="CheckedListBox.ItemCheck"/> event.
        /// </summary>
        /// <param name="e">An <see cref="ItemCheckEventArgs"/> instance that contains the event data.</param>
        protected override void OnItemCheck(ItemCheckEventArgs e)
        {
            base.OnItemCheck(e);

            if (this.isUpdatingCheckStates)
            {
                return;
            }

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

            // Update other items
            this.UpdateCheckedItems(item, e.NewValue);
        }
 /// <summary>
 /// Sets the check states of each item base on the given composite flag.
 /// </summary>
 /// <param name="p_intCompositeFlag">The composite flag value to represent with the list box.</param>
 protected void UpdateCheckedItems(Int32 p_intCompositeFlag)
 {
     for (Int32 i = 0; i < Items.Count; i++)
     {
         FlagCheckedListBoxItem lbiItem = (FlagCheckedListBoxItem)Items[i];
         if (lbiItem.Value == 0)
         {
             SetItemChecked(i, p_intCompositeFlag == 0);
         }
         else
         {
             SetItemChecked(i, (lbiItem.Value & p_intCompositeFlag) == lbiItem.Value);
         }
     }
 }
Example #9
0
        /// <summary>
        /// Gets the current bit value corresponding to all checked items.
        /// </summary>
        /// <returns>The bit value.</returns>
        private int GetCurrentValue()
        {
            int sum = 0;

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

                if (GetItemChecked(i) && item != null)
                {
                    sum |= item.Value;
                }
            }

            return(sum);
        }
Example #10
0
            // Gets the current bit value corresponding to all checked items
            public int GetCurrentValue()
            {
                int 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 #11
0
        /// <summary>
        /// Updates items in the checklistbox.
        /// </summary>
        /// <param name="composite">The item that was checked/unchecked.</param>
        /// <param name="cs">The check state of that item.</param>
        private void UpdateCheckedItems(FlagCheckedListBoxItem composite, CheckState cs)
        {
            if (composite == null)
            {
                return;
            }

            // 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++)
            {
                FlagCheckedListBoxItem item = Items[i] as FlagCheckedListBoxItem;

                if (item == null)
                {
                    continue;
                }

                // If item is checked, add its value to the sum.
                if (this.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);
            }
            else
            {
                // If the item has been checked, combine its bits with the sum
                sum |= composite.Value;
            }

            // Update all items in the checklistbox based on the final bit value
            this.UpdateCheckedItems(sum);
        }
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)
            {
                long sum = 0;

                if (composite.LongVal != 0)
                {
                    sum = Convert.ToInt64(Value);
                    // If the item has been unchecked, remove its bits from the sum
                    if (cs == CheckState.Unchecked)
                    {
                        sum = sum & ~composite.LongVal;
                    }
                    // If the item has been checked, combine its bits with the sum
                    else
                    {
                        sum |= composite.LongVal;
                    }
                }
                UpdateCheckedItems(FromLong(sum));
            }
 /// <summary>
 /// Adds a <see cref="FlagCheckedListBoxItem"/> to the list.
 /// </summary>
 /// <param name="p_lbiEnumItem">The item to add to the list.</param>
 /// <returns>The added item.</returns>
 private FlagCheckedListBoxItem Add(FlagCheckedListBoxItem p_lbiEnumItem)
 {
     Items.Add(p_lbiEnumItem);
     return(p_lbiEnumItem);
 }
			/// <summary>
			/// Adds a <see cref="FlagCheckedListBoxItem"/> to the list.
			/// </summary>
			/// <param name="p_lbiEnumItem">The item to add to the list.</param>
			/// <returns>The added item.</returns>
			private FlagCheckedListBoxItem Add(FlagCheckedListBoxItem p_lbiEnumItem)
			{
				Items.Add(p_lbiEnumItem);
				return p_lbiEnumItem;
			}
				/// <summary>
				/// Determines if the represented value's flag is set in the composite flag
				/// represented by the given item.
				/// </summary>
				/// <param name="p_lbiComposite">The item representing the composite flag for which
				/// it is to be determined if it includes this item's represented value.</param>
				/// <returns><c>true</c> if the represented value's flag is set in the composite flag
				/// represented by the given item;
				/// <c>false</c> otherwise.</returns>
				public bool IsMemberFlag(FlagCheckedListBoxItem p_lbiComposite)
				{
					return (IsFlag && ((Value & p_lbiComposite.Value) == Value));
				}
Example #16
0
        /// <summary>
        /// Updates items in the checklistbox.
        /// </summary>
        /// <param name="composite">
        /// The item that was checked/unchecked.
        /// </param>
        /// <param name="cs">
        /// The check RequestState of that item.
        /// </param>
        private void UpdateCheckedItems(FlagCheckedListBoxItem composite, CheckState cs)
        {
            if (composite == null)
            {
                return;
            }

            // 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 =
                (from object t in this.Items select t as FlagCheckedListBoxItem).Where((item, i) => item != null && this.GetItemChecked(i))
                    .Aggregate(0, (current, item) => current | item.Value);

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

            // Update all items in the checklistbox based on the final bit value
            this.UpdateCheckedItems(sum);
        }
			/// <summary>
			/// Adds an integer value to the listbox.
			/// </summary>
			/// <param name="p_intValue">The value to add to the list.</param>
			/// <param name="p_strDisplayName">The display name of the value to add.</param>
			/// <returns>The newly added <see cref="FlagCheckedListBoxItem"/> that represents the given value.</returns>
			private FlagCheckedListBoxItem Add(Int32 p_intValue, string p_strDisplayName)
			{
				FlagCheckedListBoxItem lbiEnumItem = new FlagCheckedListBoxItem(p_intValue, p_strDisplayName);
				Items.Add(lbiEnumItem);
				return lbiEnumItem;
			}
 /// <summary>
 /// Gets whether true if this value is a member of the composite bit value.
 /// </summary>
 /// <param name="composite"></param>
 /// <returns></returns>
 public bool IsMemberFlag(FlagCheckedListBoxItem composite)
 {
     return(IsFlag && ((_value & composite.Value) == _value));
 }
Example #19
0
        /// <summary>
        /// Adds an integer value and its associated description.
        /// </summary>
        /// <param name="v">
        /// The value to add.
        /// </param>
        /// <param name="c">
        /// The description string to add.
        /// </param>
        private void Add(int v, string c)
        {
            FlagCheckedListBoxItem item = new FlagCheckedListBoxItem(v, c);

            this.Items.Add(item);
        }
Example #20
0
 // Returns true if this value is a member of the composite bit value
 public bool IsMemberFlag(FlagCheckedListBoxItem composite) => (IsFlag && ((value & composite.value) == value));
 /// <summary>
 /// Determines if the represented value's flag is set in the composite flag
 /// represented by the given item.
 /// </summary>
 /// <param name="p_lbiComposite">The item representing the composite flag for which
 /// it is to be determined if it includes this item's represented value.</param>
 /// <returns><c>true</c> if the represented value's flag is set in the composite flag
 /// represented by the given item;
 /// <c>false</c> otherwise.</returns>
 public bool IsMemberFlag(FlagCheckedListBoxItem p_lbiComposite)
 {
     return(IsFlag && ((Value & p_lbiComposite.Value) == Value));
 }
Example #22
0
 public FlagCheckedListBoxItem Add(FlagCheckedListBoxItem item)
 {
     Items.Add(item);
     return(item);
 }
Example #23
0
        /// <summary>
        /// Adds an integer value and its associated description.
        /// </summary>
        /// <param name="v">The value to add.</param>
        /// <param name="c">The description string to add.</param>
        /// <returns>The <see cref="FlagCheckedListBoxItem"/> item that was added.</returns>
        private void Add(int v, string c)
        {
            FlagCheckedListBoxItem item = new FlagCheckedListBoxItem(v, c);

            Items.Add(item);
        }
 /// <summary>
 /// Gets whether true if this value is a member of the composite bit value.
 /// </summary>
 /// <param name="composite"></param>
 /// <returns></returns>
 public bool IsMemberFlag(FlagCheckedListBoxItem composite)
 {
     return (IsFlag && ((_value & composite.Value) == _value));
 }