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;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-07-22
  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-05
  • 2022-12-23
  • 2021-06-07
  • 2021-06-25
  • 2021-11-09
  • 2022-12-23
  • 2021-08-29
相关资源
相似解决方案