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)