zoukankan      html  css  js  c++  java
  • C# Combobox 设置 value

    因为ComboxItem是Object对象,而控件自身没有Value属性.所以,需要自定义一个类,用其对象来存储Text,Value.

       public class ComboxItem
        {
            private string text;
            private string values;

            public string Text
            {
                get { return this.text; }
                set { this.text = value; }
            }

            public string Values
            {
                get { return this.values; }
                set { this.values = value; }
            }

            public ComboxItem(string _Text, string _Values)
            {
                Text = _Text;
                Values = _Values;
            }


            public override string ToString()
            {
                return Text;
            }
        }


    赋值示例一:

         cbDictData.Items.Add(new ComboxItem("用户类型", "D1"));
                cbDictData.Items.Add(new ComboxItem("地区字典", "D2"));
                cbDictData.Items.Add(new ComboxItem("区域字典", "D3")); 
      
    赋值示例二:

     ComboxItem[] values = {
                    new ComboxItem("用户类型", "D1"),
                    new ComboxItem("地区字典", "D2"),
                    new ComboxItem("区域字典", "D3")
                };
                cbDictData.Items.AddRange(values);

    取值示例:

    string strDict = ((ComboxItem)cbDictData.SelectedItem).Values;

  • 相关阅读:
    Oracle学习笔记<5>
    Oracle学习笔记<4>
    fabric动态获取远程目录列表
    fabric查看本地与远程主机信息
    fabric安装使用
    pexpect实现远程操作
    pexpect的pxssh类实现远程操作
    Most Distant Point from the Sea
    Art Gallery
    Rotating Scoreboard(半平面交模板题)
  • 原文地址:https://www.cnblogs.com/ggll611928/p/5984542.html
Copyright © 2011-2022 走看看