随笔 - 61  文章 - 10  评论 - 370 

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”;
newItem.Value = “1”;
ComboBox1.Items.Add(newItem);

取值的时候又没有注意到selectedvalue是取自ValueMember所以忘了强制转换类型,浪费了我一小时的时间。。

取值使用方法:
ComboBoxItem myItem = (ComboBoxItem)ComboBox1.Items[0];
string strValue = myItem.Value;

posted on 2006-01-17 15:00 杨丹 阅读(702) 评论(3) 编辑 收藏