免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1743 | 回复: 2
打印 上一主题 下一主题

扩展ComboBox类的项--ComboBoxItem [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-21 01:41 |只看该作者 |倒序浏览
  1. Class的定义
  2. public class ComboBoxItem
  3. {
  4.   private string _text=null;
  5.   private object _value=null;
  6.   public string Text
  7.   {
  8.    get{return this._text;}
  9.    set{this._text=value;}
  10.   }
  11.   public object Value
  12.   {
  13.    get {return this._value;}
  14.    set{this._value=value;}
  15.   }

  16.   public override string ToString()
  17.   {
  18.    return this._text;
  19.   }
  20. }


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

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

复制代码

论坛徽章:
0
2 [报告]
发表于 2011-02-22 00:08 |只看该作者
呵呵
最近做任务编辑器用到了这个控件

论坛徽章:
324
射手座
日期:2013-08-23 12:04:38射手座
日期:2013-08-23 16:18:12未羊
日期:2013-08-30 14:33:15水瓶座
日期:2013-09-02 16:44:31摩羯座
日期:2013-09-25 09:33:52双子座
日期:2013-09-26 12:21:10金牛座
日期:2013-10-14 09:08:49申猴
日期:2013-10-16 13:09:43子鼠
日期:2013-10-17 23:23:19射手座
日期:2013-10-18 13:00:27金牛座
日期:2013-10-18 15:47:57午马
日期:2013-10-18 21:43:38
3 [报告]
发表于 2011-02-22 08:40 |只看该作者
是Java?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP