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;

  • 相关阅读:
    实验四Web服务器2
    发际线与我作队团队作业(五):冲刺总结1
    读书笔记
    socket3
    使用CAS来实现个单例模式
    基于无锁的C#并发队列实现
    C#3.0中的“多重继承”
    对并发/并行编程的总结
    谈谈多线程编程(二) 不变对象
    谈谈多线程编程(一) 安全性策略
  • 原文地址:https://www.cnblogs.com/ggll611928/p/5984542.html
Copyright © 2011-2022 走看看