C # WinForm Key value type data how to bind Combox (hashtable,keyvaluepair,dictionary)

Source: Internet
Author: User

Cbuseragent is a Combox
ArrayList list =NewArrayList (); Dictionary<string,string> useragents =Newdictionary<string,string>(); /// <summary>        ///Initialize Combox/// </summary>        Private voidinitcbuseragent () {cbUserAgent.Items.Clear (); List.            Clear (); Useragents.            Clear (); //Method 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> Ainchuseragents) {list.            Add (a); }            //Method 2//Hashtable myhash = null; //Myhash = new Hashtable (); //Myhash.add ("jianbing", "I am Chinese 1"); //Myhash.add ("CH", "I Love my Motherland 2"); //Myhash.add ("U", "You are silly Big wood 3"); //Myhash.add ("M", "I want to find a mm love 4"); //Myhash.add ("MM", "because I want someone who loves me 5"); //Myhash.add ("MI", "I want a girl who is really good to me 6"); //System.Collections.ArrayList list = new System.Collections.ArrayList (); //foreach (DictionaryEntry entry in Myhash)//list.            ADD (entry); //bind this damned drop-down listCbuseragent.datasource =list; Cbuseragent.displaymember="Key"; Cbuseragent.valuemember="Value"; //Method Three://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); //}        }

Refer to Hashtable for more information: http://jambulshines.blog.163.com/blog/static/119498161200959175355/

C # WinForm Key value type data how to bind Combox (hashtable,keyvaluepair,dictionary)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.