/// <summary> /// List /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CheckedListBoxCommon_Leave(object sender, EventArgs e) { if (checkedListBox.Items.Count > 0) { this.Text = string.Empty; CheckedItemKeys = new List <object>(); CheckedItemValues = new List <object>(); for (int i = 0; i < checkedListBox.CheckedItems.Count; i++) { string name = checkedListBox.GetItemText(checkedListBox.CheckedItems[i]).ToString(); int itemIndex = checkedListBox.Items.IndexOf(checkedListBox.CheckedItems[i]); checkedListBox.SetSelected(itemIndex, true); var value = checkedListBox.SelectedValue; CheckedItemKeys.Add(value); CheckedItemValues.Add(name); } if (this.CheckedItemValues.Count > 0) { this.Text = string.Join(",", this.CheckedItemValues); } } this.FindForm().Controls.Remove(checkedListBox); checkedListBox = null; }
/// <summary> /// add checkedlistboxcommon on mouseclick on combobox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComboBoxMultiSelectOrder_MouseClick(object sender, EventArgs e) { if (checkedListBox != null) { this.FindForm().Controls.Remove(checkedListBox); checkedListBox = null; return; } checkedListBox = new CheckedListBoxCommon(); if (DataSource == null) { return; } this.checkedListBox.DataSource = this.DataSource; this.checkedListBox.DisplayMember = this.DisplayMember; this.checkedListBox.ValueMember = this.ValueMember; checkedListBox.Height = 100; checkedListBox.Width = this.Width; if (this.Parent is FormCommonBase) { checkedListBox.Location = new System.Drawing.Point(this.Left, (this.Location.Y + this.Height)); } else { checkedListBox.Location = new System.Drawing.Point(this.Parent.Location.X + this.Location.X, (this.Parent.Location.Y + this.Location.Y + this.Height)); } this.FindForm().Controls.Add(checkedListBox); checkedListBox.BringToFront(); checkedListBox.Focus(); SetCheckedList(); this.checkedListBox.Leave += new EventHandler(CheckedListBoxCommon_Leave); this.checkedListBox.ItemCheck += new ItemCheckEventHandler(CheckedListBoxCommon_ItemCheck); }