zoukankan      html  css  js  c++  java
  • C# 中combobox 控件初始化

    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; }
            }
        }

  • 相关阅读:
    五,系统操作命令说明
    三,linux系统的由来
    二,服务器磁盘阵列(raid)
    一服务器硬件介绍
    四,元组类型
    集合类型
    字典类型
    三,列表类型
    二,字符串类型
    一,数字类型
  • 原文地址:https://www.cnblogs.com/sunleinote/p/2220416.html
Copyright © 2011-2022 走看看