| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
-
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Windows.Forms;
- namespace Dongke.WinForm.Controls
- {
- /// <summary>
- /// 多选下拉框控件
- /// </summary>
- [ToolboxBitmap(typeof(ComboBox))]
- public partial class CkcCheckedComboBox : PopupComboBox
- {
- #region 成员变量
- /// <summary>
- /// 全选ListBox
- /// </summary>
- private CalCheckAllListBox _calListBox = new CalCheckAllListBox();
- #endregion
- #region 构造函数
- /// <summary>
- /// 多选下拉框控件
- /// </summary>
- 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 属性
- /// <summary>
- /// 获取或设置全选CheckBox的Text。
- /// </summary>
- [Description("获取或设置全选CheckBox的Text。"), Category("CustomerEx")]
- [DefaultValue("全部")]
- public string TextAll
- {
- get
- {
- return this._calListBox.TextAll;
- }
- set
- {
- this._calListBox.TextAll = value;
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示此全选是否允许三种复选状态而不是两种。
- /// </summary>
- [Description("获取或设置一个值,该值指示此全选是否允许三种复选状态而不是两种。"), Category("CustomerEx")]
- [DefaultValue(false)]
- public bool ThreeState
- {
- get
- {
- return this._calListBox.ThreeState;
- }
- set
- {
- this._calListBox.ThreeState = value;
- }
- }
- /// <summary>
- /// 获取选中的文本
- /// </summary>
- [Description("获取选中的文本。"), Category("CklCheckedListBox")]
- [DefaultValue(null)]
- public string[] CheckedTexts
- {
- get
- {
- return this._calListBox.CheckedTexts;
- }
- }
- /// <summary>
- /// 获取选中的值
- /// </summary>
- [Description("获取选中的值。"), Category("CklCheckedListBox")]
- [DefaultValue(null)]
- public object[] CheckedValues
- {
- get
- {
- return this._calListBox.CheckedValues;
- }
- }
- /// <summary>
- /// 获取选中项的文本表示形式,用【,】隔开。
- /// </summary>
- [Description("获取选中项的文本表示形式,用【,】隔开。"), Category("CklCheckedListBox")]
- [DefaultValue(null)]
- public string CheckedText
- {
- get
- {
- return this._calListBox.CheckedText;
- }
- }
- /// <summary>
- /// 获取选中项的值,用【,】隔开
- /// </summary>
- [Description("获取选中项的值,用【,】隔开。"), Category("CklCheckedListBox")]
- [DefaultValue(null)]
- public string CheckedValue
- {
- get
- {
- return this._calListBox.CheckedValue;
- }
- }
- ///// <summary>
- ///// 获取或设置控件是否单项选中。
- ///// </summary>
- //[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;
- // }
- //}
- /// <summary>
- /// 该控件中选中索引的集合。
- /// </summary>
- [Description("该控件中选中索引的集合。"), Category("CheckedListBox")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public CheckedListBox.CheckedIndexCollection CheckedIndices
- {
- get
- {
- return this._calListBox.CheckedIndices;
- }
- }
- /// <summary>
- /// 该控件中选中项的集合。
- /// </summary>
- [Description("该控件中选中项的集合。"), Category("CheckedListBox")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public CheckedListBox.CheckedItemCollection CheckedItems
- {
- get
- {
- return this._calListBox.CheckedItems;
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示当选定项时是否应切换复选框。
- /// </summary>
- [Description("获取或设置一个值,该值指示当选定项时是否应切换复选框。"), Category("CheckedListBox")]
- [DefaultValue(true)]
- public bool CheckOnClick
- {
- get
- {
- return this._calListBox.CheckOnClick;
- }
- set
- {
- this._calListBox.CheckOnClick = value;
- }
- }
- /// <summary>
- /// 获取或设置全部项目的选中状态。
- /// </summary>
- [DefaultValue(typeof(CheckState), "Unchecked")]
- [Description("获取或设置全部项目的选中状态。"), Category("CustomerEx")]
- public CheckState CheckedState
- {
- get
- {
- return this._calListBox.CheckedState;
- }
- set
- {
- this._calListBox.CheckedState = value;
- }
- }
- #endregion
- #region 重写属性
- /// <summary>
- /// 获取或设置控件的数据源
- /// </summary>
- [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;
- }
- }
- /// <summary>
- /// 获取或设置控件的显示的属性
- /// </summary>
- [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;
- }
- }
- /// <summary>
- /// 获取或设置一个属性,该属性将用作控件中的项的实际值。
- /// </summary>
- [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;
- }
- }
- /// <summary>
- /// 获取该控件中项的集合。
- /// </summary>
- [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;
- }
- }
- /// <summary>
- /// 获取或设置控件是否必须选中项目。
- /// </summary>
- 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 重写方法
- /// <summary>
- /// 输入验证时,设定默认值。
- /// </summary>
- protected override void SetDefaultOnCheck()
- {
- //if (this._mustInput && this.SelectedIndex < 0 && this.Items.Count > 0)
- //{
- // this.SelectedIndex = 0;
- //}
- }
- /// <summary>
- /// 验证输入内容
- /// </summary>
- /// <returns>验证结果</returns>
- 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;
- }
- /// <summary>
- /// 清除输入项
- /// </summary>
- public override void ClearValue()
- {
- this._calListBox.ClearValue();
- }
- #endregion
- #region 事件处理
- /// <summary>
- /// 项目选中事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CalListBox_ItemChecked(object sender, ItemCheckedEventArgs e)
- {
- //this.Text = this._calListBox.CheckedText;
- this.SetText(this._calListBox.CheckedText);
- this.ValidateData();
- }
- #endregion
- #region 公有方法
- /// <summary>
- /// 获取指定项的成员属性的值
- /// </summary>
- /// <param name="item">项</param>
- /// <returns>值</returns>
- public virtual object GetItemValue(object item)
- {
- return this._calListBox.GetItemValue(item);
- }
- /// <summary>
- /// 获取选中项的文本表示形式
- /// </summary>
- /// <returns>选中项的文本</returns>
- public virtual List<string> GetCheckedItemTexts()
- {
- return this._calListBox.GetCheckedItemTexts();
- }
- /// <summary>
- /// 获取选中项的成员属性的值
- /// </summary>
- /// <returns>选中项的值</returns>
- public virtual List<object> GetCheckedItemValues()
- {
- return this._calListBox.GetCheckedItemValues();
- }
- /// <summary>
- /// 获取选中项的成员属性的值
- /// </summary>
- /// <typeparam name="T">属性值的类型</typeparam>
- /// <returns>选中项的值</returns>
- public virtual List<T> GetCheckedItemValues<T>()
- {
- return this._calListBox.GetCheckedItemValues<T>();
- }
- /// <summary>
- /// 设定全部项的复选状态
- /// </summary>
- /// <param name="value">若要将该项设置为选中,则为 true;否则为 false</param>
- public virtual void SetAllItemsChecked(bool value)
- {
- this._calListBox.SetAllItemsChecked(value);
- }
- /// <summary>
- /// 设置全部项目选中状态
- /// </summary>
- /// <param name="value">若要将该项设置为选中,则为 true;否则为 false</param>
- public virtual void SetAllItemsChecked(CheckState value)
- {
- this._calListBox.SetAllItemsChecked(value);
- }
- /// <summary>
- /// 获取全部项的复选状态
- /// </summary>
- /// <returns>选中状态</returns>
- public virtual CheckState GetItemsCheckState()
- {
- return this._calListBox.GetItemsCheckState();
- }
- /// <summary>
- /// 设定指定项的复选状态
- /// </summary>
- /// <param name="value">若要将该项设置为选中,则为 true;否则为 false</param>
- /// <param name="items">要为其设置复选状态的项</param>
- public virtual void SetItemCheckedByItem(bool value, params object[] items)
- {
- this._calListBox.SetItemCheckedByItem(value, items);
- }
- /// <summary>
- /// 设定指定值的项的复选状态
- /// </summary>
- /// <param name="value">若要将该项设置为选中,则为 true;否则为 false</param>
- /// <param name="itemValues">要为其设置复选状态的项的值</param>
- public virtual void SetItemCheckedByValue(bool value, params object[] itemValues)
- {
- this._calListBox.SetItemCheckedByValue(value, itemValues);
- }
- /// <summary>
- /// 设定指定索引处的项目选中或取消
- /// </summary>
- /// <param name="value">若要将该项设置为选中,则为 true;否则为 false</param>
- /// <param name="indexs">要为其设置复选状态的项的索引</param>
- public void SetItemChecked(bool value, params int[] indexs)
- {
- this._calListBox.SetItemCheckedByValue(value, indexs);
- }
- /// <summary>
- /// 设置指定索引处项的复选状态
- /// </summary>
- /// <param name="index">要为其设置状态的项的索引</param>
- /// <param name="value">若要将该项设置为选中,则为 true;否则为 false</param>
- public void SetItemChecked(int index, bool value)
- {
- this._calListBox.SetItemChecked(index, value);
- }
- /// <summary>
- /// 设置指定索引处项的复选状态
- /// </summary>
- /// <param name="index">要为其设置状态的项的索引</param>
- /// <param name="value">System.Windows.Forms.CheckState 值之一</param>
- public void SetItemCheckState(int index, CheckState value)
- {
- this._calListBox.SetItemCheckState(index, value);
- }
- #endregion
- #region 内部方法
- #endregion
- #region 保护方法
- #endregion
- #region 私有方法
- #endregion
- }
- }
|