using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
namespace Dongke.WinForm.Controls
{
///
/// 多选下拉框控件
///
[ToolboxBitmap(typeof(ComboBox))]
public partial class CkcCheckedComboBox : PopupComboBox
{
#region 成员变量
///
/// 全选ListBox
///
private CalCheckAllListBox _calListBox = new CalCheckAllListBox();
#endregion
#region 构造函数
///
/// 多选下拉框控件
///
public CkcCheckedComboBox()
{
base.FormattingEnabled = false;
this._calListBox.ShowMustInputAlert = false;
this._calListBox.InputErrorAlert = InputErrorAlert.None;
this._calListBox.ShowBorderColor = false;
this._calListBox.BorderStyle = BorderStyle.None;
this._calListBox.ItemChecked += CalListBox_ItemChecked;
this.DropDownControl = this._calListBox;
this.ShowComboBoxDropDown = false;
}
#endregion
#region 属性
///
/// 获取或设置全选CheckBox的Text。
///
[Description("获取或设置全选CheckBox的Text。"), Category("CustomerEx")]
[DefaultValue("全部")]
public string TextAll
{
get
{
return this._calListBox.TextAll;
}
set
{
this._calListBox.TextAll = value;
}
}
///
/// 获取或设置一个值,该值指示此全选是否允许三种复选状态而不是两种。
///
[Description("获取或设置一个值,该值指示此全选是否允许三种复选状态而不是两种。"), Category("CustomerEx")]
[DefaultValue(false)]
public bool ThreeState
{
get
{
return this._calListBox.ThreeState;
}
set
{
this._calListBox.ThreeState = value;
}
}
///
/// 获取选中的文本
///
[Description("获取选中的文本。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public string[] CheckedTexts
{
get
{
return this._calListBox.CheckedTexts;
}
}
///
/// 获取选中的值
///
[Description("获取选中的值。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public object[] CheckedValues
{
get
{
return this._calListBox.CheckedValues;
}
}
///
/// 获取选中项的文本表示形式,用【,】隔开。
///
[Description("获取选中项的文本表示形式,用【,】隔开。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public string CheckedText
{
get
{
return this._calListBox.CheckedText;
}
}
///
/// 获取选中项的值,用【,】隔开
///
[Description("获取选中项的值,用【,】隔开。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public string CheckedValue
{
get
{
return this._calListBox.CheckedValue;
}
}
/////
///// 获取或设置控件是否单项选中。
/////
//[Description("获取或设置控件是否单项选中。"), Category("CustomerEx")]
//[DefaultValue(false)]
//[Browsable(false)]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//public bool SimpleChecked
//{
// get
// {
// return this._calListBox.SimpleChecked;
// }
// set
// {
// this._calListBox.SimpleChecked = value;
// }
//}
///
/// 该控件中选中索引的集合。
///
[Description("该控件中选中索引的集合。"), Category("CheckedListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public CheckedListBox.CheckedIndexCollection CheckedIndices
{
get
{
return this._calListBox.CheckedIndices;
}
}
///
/// 该控件中选中项的集合。
///
[Description("该控件中选中项的集合。"), Category("CheckedListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public CheckedListBox.CheckedItemCollection CheckedItems
{
get
{
return this._calListBox.CheckedItems;
}
}
///
/// 获取或设置一个值,该值指示当选定项时是否应切换复选框。
///
[Description("获取或设置一个值,该值指示当选定项时是否应切换复选框。"), Category("CheckedListBox")]
[DefaultValue(true)]
public bool CheckOnClick
{
get
{
return this._calListBox.CheckOnClick;
}
set
{
this._calListBox.CheckOnClick = value;
}
}
///
/// 获取或设置全部项目的选中状态。
///
[DefaultValue(typeof(CheckState), "Unchecked")]
[Description("获取或设置全部项目的选中状态。"), Category("CustomerEx")]
public CheckState CheckedState
{
get
{
return this._calListBox.CheckedState;
}
set
{
this._calListBox.CheckedState = value;
}
}
#endregion
#region 重写属性
///
/// 获取或设置控件的数据源
///
[Description("获取或设置控件的数据源。"), Category("ListControl")]
[AttributeProvider(typeof(IListSource))]
[DefaultValue(null)]
[RefreshProperties(RefreshProperties.Repaint)]
public override object DataSource
{
get
{
return this._calListBox.DataSource;
}
set
{
this._calListBox.DataSource = value;
}
}
///
/// 获取或设置控件的显示的属性
///
[Description("获取或设置控件的显示的属性。"), Category("ListControl")]
//[DefaultValue(null)]
[DefaultValue("")]
[Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public new string DisplayMember
{
get
{
return this._calListBox.DisplayMember;
}
set
{
this._calListBox.DisplayMember = value;
}
}
///
/// 获取或设置一个属性,该属性将用作控件中的项的实际值。
///
[Description("获取或设置一个属性,该属性将用作控件中的项的实际值。"), Category("ListControl")]
//[DefaultValue(null)]
[DefaultValue("")]
[Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public new string ValueMember
{
get
{
return this._calListBox.ValueMember;
}
set
{
this._calListBox.ValueMember = value;
}
}
///
/// 获取该控件中项的集合。
///
[Description("获取该控件中项的集合。"), Category("ListControl")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Localizable(true)]
[MergableProperty(false)]
public new CheckedListBox.ObjectCollection Items
{
get
{
return this._calListBox.Items;
}
}
///
/// 获取或设置控件是否必须选中项目。
///
public override bool MustInput
{
get
{
return base.MustInput;
}
set
{
//this._calListBox.MustInput = value;
base.MustInput = value;
}
}
#endregion
#region 重写事件
#region 属性改变
#endregion
#region 行为事件
#endregion
#region 键盘事件
#endregion
#region 焦点事件
#endregion
#region 鼠标事件
#endregion
#endregion
#region 重写方法
///
/// 输入验证时,设定默认值。
///
protected override void SetDefaultOnCheck()
{
//if (this._mustInput && this.SelectedIndex < 0 && this.Items.Count > 0)
//{
// this.SelectedIndex = 0;
//}
}
///
/// 验证输入内容
///
/// 验证结果
public override bool ValidateData()
{
if (this.MustInput && this.CheckedState == CheckState.Unchecked)
{
this.SetError(true, ControlErrorCode.DKC_0001, this.CDItemName);
return false;
}
this.ClearError();
return true;
}
///
/// 清除输入项
///
public override void ClearValue()
{
this._calListBox.ClearValue();
}
#endregion
#region 事件处理
///
/// 项目选中事件
///
///
///
private void CalListBox_ItemChecked(object sender, ItemCheckedEventArgs e)
{
//this.Text = this._calListBox.CheckedText;
this.SetText(this._calListBox.CheckedText);
this.ValidateData();
}
#endregion
#region 公有方法
///
/// 获取指定项的成员属性的值
///
/// 项
/// 值
public virtual object GetItemValue(object item)
{
return this._calListBox.GetItemValue(item);
}
///
/// 获取选中项的文本表示形式
///
/// 选中项的文本
public virtual List GetCheckedItemTexts()
{
return this._calListBox.GetCheckedItemTexts();
}
///
/// 获取选中项的成员属性的值
///
/// 选中项的值
public virtual List