public int GetIndex(DropDownListItem item) { if (this.ucItemPanel.Controls.Contains(item)) { return(this.ucItemPanel.Controls.GetChildIndex(item)); } return(-1); }
/// <summary> /// 删除一项 /// </summary> /// <param name="item"></param> public void Remove(DropDownListItem item) { if (this.ucItemPanel.Controls.Contains(item)) { this.ucItemPanel.Controls.Remove(item); item.Click -= new EventHandler(DropDownListItem_Click); } }
void DropDownListItem_Click(object sender, EventArgs e) { DropDownListItem currentItem = sender as DropDownListItem; if (ItemClicked != null) { ItemClicked(this, currentItem); } }
/// <summary> /// 增加一项 /// </summary> /// <param name="item"></param> public void Add(DropDownListItem item) { if (!this.ucItemPanel.Controls.Contains(item)) { this.ucItemPanel.Controls.Add(item); this.ucItemPanel.Controls.SetChildIndex(item, this.ucItemPanel.Controls.Count - 1); if (_linkedControl != null) { item.ForeColor = _linkedControl.ForeColor; } item.Click += new EventHandler(DropDownListItem_Click); } }
private void SetSelectedValue(DropDownListItem value) { bool hasChanged = selectedItem != value; var previousItem = selectedItem; selectedItem = value; if (hasChanged) { if (selectedItem == null) { this.Text = string.Empty; } else { this.Text = selectedItem.Text; } if (this.SelectionChanged != null) { SelectionChanged(this, previousItem, selectedItem); } } }
void frmDropDownList_ItemClicked(object sender, DropDownListItem e) { this.SelectedItem = e; this.frmDropDownList.Hide(); }
public bool Contains(DropDownListItem item) { return(this.ucItemPanel.Controls.Contains(item)); }