C# winform key value型資料如何綁定ComBox (hashtable,keyvaluepair,dictionary )

來源:互聯網
上載者:User

標籤:

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/

 

C# winform key value型資料如何綁定ComBox (hashtable,keyvaluepair,dictionary )

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.