扩展ComboBox类的项ComboBoxItem

发表时间:2006-4-12 23:18:00

Class的定义
public class ComboBoxItem
 {
  private string _text=null;
  private object _value=null;
  public string Text
  {
   get{return this._text;}
   set{this._text=value;}
  }
  public object Value
  {
   get {return this._value;}
   set{this._value=value;}
  }

  public override string ToString()
  {
   return this._text;
  }
 }


赋值:
ComboBoxItem newItem = new ComboBoxItem();
newItem.Text = "abc"+i.ToString();
newItem.Value = "value"+i.ToString();
comboBox1.Items.Add(newItem);

取值:
ComboBoxItem myItem = (ComboBoxItem)comboBox1.Items[0];
string strValue = myItem.Value.ToString();
MessageBox.Show(strValue);

原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1446297.html