zoukankan      html  css  js  c++  java
  • C# winform key value型数据如何绑定ComBox (hashtable,keyvaluepair,dictionary )

    cbUserAgent是一个combox
            ArrayList list = new ArrayList();
            Dictionary<string, string> useragents = new Dictionary<string, string>();
    
            /// <summary>
            /// 初始化combox
            /// </summary>
            private void InitCbUserAgent()
            {
               
                cbUserAgent.Items.Clear();
                list.Clear();
                useragents.Clear();
                //方法1:
                useragents.Add("IE7", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");
                useragents.Add("IE8", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");
                useragents.Add("IE9", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");
                useragents.Add("IE10", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");
                useragents.Add("Chrome39.0", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
                useragents.Add("Firefox34.0", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
    
                foreach (KeyValuePair<string, string> a in useragents)
                {
                    list.Add(a);
                }
    
                //方法2
              
                //Hashtable myHash = null;
                //myHash = new Hashtable();
                //myHash.Add("JIANBING", "我是中国人1");
                //myHash.Add("CH", "我爱我的祖国2");
                //myHash.Add("U", "你是傻大木3");
                //myHash.Add("M", "我想找个MM谈恋爱4");
                //myHash.Add("MM", "因为我想有人疼爱我5");
                //myHash.Add("MI", "我想要个真心对我好的的女孩6");
                //System.Collections.ArrayList list = new System.Collections.ArrayList();
                //foreach (DictionaryEntry entry in myHash)
                //list.Add(entry);
    
                //绑定这该死的 下拉列表 
                cbUserAgent.DataSource = list;
                cbUserAgent.DisplayMember = "Key";
                cbUserAgent.ValueMember = "Value";
    
               //方法三:
                //KeyValuePair<string, string> ukp = new KeyValuePair<string, string>();
                //foreach (string key in useragents.Keys)
                //{
                //    ukp = new KeyValuePair<string, string>(key, useragents[key]);
                //    cbUserAgent.Items.Add(ukp);
                //}
    
            }

    关于hashtable可参考:http://jambulshines.blog.163.com/blog/static/119498161200959175355/

  • 相关阅读:
    springMVC的@RequestMapping的参数和用法
    springMVC的helloword
    eclipse 导入MyEclipse创建的web项目该如何启动?
    解决mysql中文乱码
    java核心技术 卷1 基础知识—对象与继承
    Java核心技术 卷1 基础知识—概述、环境
    python爬虫框架之scrapy的快速上手
    如何评测软件工程知识技能水平
    金融文本挖掘的业务领域建模
    金融文本挖掘中的针对业务的用例建模
  • 原文地址:https://www.cnblogs.com/amosli/p/4239850.html
Copyright © 2011-2022 走看看