using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace Microsoft.Win32.TaskScheduler
{
///
/// A check list in a drop down combo box.
///
[System.Drawing.ToolboxBitmap(typeof(Microsoft.Win32.TaskScheduler.TaskEditDialog), "Control")]
public partial class DropDownCheckList : CustomComboBox
{
private System.Windows.Forms.CheckedListBox checkedListBox1;
private int lastCheckHash = 0;
private Timer onCheckTimer;
private bool privateSet = false;
///
/// Initializes a new instance of the class.
///
public DropDownCheckList()
{
this.onCheckTimer = new Timer { Interval = 150 };
this.onCheckTimer.Tick += onCheckTimer_Tick;
this.checkedListBox1 = new System.Windows.Forms.CheckedListBox()
{
BorderStyle = System.Windows.Forms.BorderStyle.None,
CheckOnClick = true,
FormattingEnabled = true,
Location = new System.Drawing.Point(17, 35),
MultiColumn = false,
Name = "checkedListBox1",
Size = new System.Drawing.Size(187, 105),
TabIndex = 0
};
this.checkedListBox1.ItemCheck += new ItemCheckEventHandler(checkedListBox1_ItemCheck);
base.DropDownControl = this.checkedListBox1;
}
///
/// Occurs when the property changes.
///
[Category("Action"), Description("Occurs when the SelectedItems property changes.")]
public event EventHandler SelectedItemsChanged;
///
/// Gets or sets a value indicating whether to allow only one checked item.
///
/// true if allowing only one checked item; otherwise, false.
[Category("Behavior"), DefaultValue(false)]
public bool AllowOnlyOneCheckedItem { get; set; }
///
/// Gets or sets the text used on the Check All Items item that, when clicked, will check all the other items.
///
/// The text.
[DefaultValue((string)null), Category("Appearance"), Localizable(true)]
public string CheckAllText { get; set; }
///
/// Gets or sets the logical AND value of all checked items.
///
/// The checked flags bitwise value.
[DefaultValue(0L), Category("Data"), Browsable(false)]
public long CheckedFlagValue
{
get
{
long ret = 0;
for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
{
object o = checkedListBox1.CheckedItems[i];
if (o is DropDownCheckListItem)
o = ((DropDownCheckListItem)o).Value;
try { ret |= Convert.ToInt64(o); }
catch {}
}
return ret;
}
set
{
privateSet = true;
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
long? val = null;
object o = checkedListBox1.Items[i];
if (checkedListBox1.Items[i] is DropDownCheckListItem)
o = ((DropDownCheckListItem)o).Value;
try { val = Convert.ToInt64(o); }
catch { }
if (val.HasValue && (val.Value & value) == val.Value)
this.checkedListBox1.SetItemCheckState(i, CheckState.Checked);
else
this.checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
}
privateSet = false;
CheckedItemsChanged();
}
}
///
/// Gets or sets a value indicating whether formatting is applied to the property of the .
///
///
/// true if formatting of the property is enabled; otherwise, false. The default is false.
///
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new bool FormattingEnabled
{
get { return base.FormattingEnabled; }
set { base.FormattingEnabled = value; }
}
///
/// Gets the list of all check list items.
///
/// The items.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("Data")]
public new CheckedListBox.ObjectCollection Items
{
get { return this.checkedListBox1.Items; }
}
///
/// Gets or sets a value indicating whether to display the list with multiple columns.
///
/// true if multi-column; otherwise, false.
[DefaultValue(false), Category("Appearance")]
public bool MultiColumnList
{
get { return this.checkedListBox1.MultiColumn; }
set { this.checkedListBox1.MultiColumn = value; }
}
///
/// Gets the selected items.
///
/// The selected items.
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DropDownCheckListItem[] SelectedItems
{
get
{
var c = this.checkedListBox1.CheckedItems;
DropDownCheckListItem[] ret = new DropDownCheckListItem[c.Count];
for (int i = 0; i < ret.Length; i++)
{
ret[i] = c[i] as DropDownCheckListItem;
if (ret[i] == null)
ret[i] = new DropDownCheckListItem(c[i]);
}
return ret;
}
}
///
/// Gets or sets a value indicating whether the items in the combo box are sorted.
///
/// true if the combo box is sorted; otherwise, false. The default is false.
///
/// An attempt was made to sort a that is attached to a data source.
///
///
///
///
///
///
///
public new bool Sorted
{
get { return this.checkedListBox1.Sorted; }
set { this.checkedListBox1.Sorted = value; }
}
///
/// Checks the matching items.
///
/// The match.
/// if set to true keep existing checked items.
public void CheckItems(Predicate