• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#中combobox控件初始化

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.从工具箱中找到combobox控件图标拖到winform界面上,IDE会自动生成一个combobox控件,控件名称为comboBox1.

2.在Form1_Load()函数中添加如下代码:

           ArrayList lst = new ArrayList();       //列表
            lst.Add(new Vendor("a_geshi03", "20"));  //在列表中增加对象
            lst.Add(new Vendor("a_geshi04", "30"));

            comboBox1.Items.Clear();                 //清空combobox
            comboBox1.DataSource = lst;           //将lst列表绑定到combobx
            comboBox1.DisplayMember ="Strtemname";// 指定显示的数据项
            comboBox1.ValueMember =  "Strindex";  //指定comboBox1.SelectedValue返回的数据项

3.其中的Vendor可以是自定义的类,如:

  class Vendor
    {
        private string strtemname;
        private string strindex;
        public Vendor(string itemname,string index)
        {
            this.strtemname = itemname;
            this.strindex = index;
        }

        public string Strtemname
        {
            get { return strtemname; }
            set { strtemname = value; }
        }

        public string Strindex
        {
            get { return strindex; }
            set { strindex = value; }
        }
    }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#判断一个string是否为数字发布时间:2022-07-10
下一篇:
C#语法初始化字段发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap