Custom Search
Logiclabz

Use Key Value pair in .Net ComboBox

//Add a public class for key value pair concept

public class KeyValuePair
    {
 
        public object Key; 
        public string Value
     
        public KeyValuePair(object NewValue,string NewDescription)
        {
             Key = NewValue
            Value = NewDescription
        }
     
        public override string ToString()
        {
            return Value
        }
    }


//add item to combo box using keyvalue pair class

cmbTopSites.Items.Add(new KeyValuePair("100","Top 100 sites";))

//key and values of the selected item can be accessed as below

KeyValuePair maxPages = (KeyValuePair)cmbTopSites.SelectedItem
string skey = maxPages.Key.ToString()
string svalue = maxPages.value.ToString()



Leave a reply


Do you like this post?