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;

  • 相关阅读:
    Microsoft.Office.Inter.Excel.dll在調用時可能會出現如下錯誤
    Proe 导出PDF Vb.net
    给Eclipse安装Google app engine插件
    VC++ 2013 开发windows窗体程序
    GitHub使用说明
    c# 发送邮件
    c# aes 加密解密
    sourceforge软件下载方式
    keyCode转换成值
    前端写代码自动刷新神器Browsersync
  • 原文地址:https://www.cnblogs.com/ggll611928/p/5984542.html
Copyright © 2011-2022 走看看