你的想法很重要-大家都来谈 (C)Copyright 2012 by WeiPt

手动添加winform的combobox和listbox名称和值

先定义一个ListItem类,工程内其他窗体都可以用的。 
public class ListItem : Object
    {
        public string Text { get; set; }
        public string Value { get; set; }
        public ListItem(string text, string value)
        {
            this.Text = text;
            this.Value = value;
        }
        public override string ToString()
        {
            return this.Text;
        }
    }
=========================================================
使用时:
ListItem li=new ListItem("名称","键值");
之后就可以把li添加到combobox和listbox控件
combobox1.items.add(li);
微软越来越来懒了,像这种常用的东西都不提供了,还要自己写。哎
posted @ 2017-09-21 17:59  weipt  阅读(260)  评论(1编辑  收藏  举报

你的想法很重要-大家都来谈 (C)Copyright 2012 by WeiPt