/* All code in this file Copyright G Himangi * Downloaded from http://www.codeproject.com/useritems/flagenumeditor.asp * Modified the Namespace just because it was too generic. * Added DesignTimeVisible(false) to hide it from the toolbox. */ using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; using System.Drawing.Design; using System.Windows.Forms.Design; namespace ScintillaNET.Design { [DesignTimeVisible(false)] public class FlagCheckedListBox : CheckedListBox { private System.ComponentModel.Container components = null; public FlagCheckedListBox() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // TODO: Add any initialization after the InitForm call } protected override void Dispose(bool disposing) { if(disposing) { if(components != null) components.Dispose(); } base.Dispose(disposing); } #region Component Designer generated code private void InitializeComponent() { // // FlaggedCheckedListBox // this.CheckOnClick = true; } #endregion // 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; } public FlagCheckedListBoxItem Add(FlagCheckedListBoxItem item) { Items.Add(item); return item; } 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); } // Checks/Unchecks items depending on the give bitvalue protected void UpdateCheckedItems(int value) { isUpdatingCheckStates = true; // Iterate over all items for(int i=0; i