把Dictionary绑定到combox

代码
 private void bindCBSessionTimeOut()
        {
            IList
<DictionaryEntry> List = new List<DictionaryEntry>();
            List.Add(
new DictionaryEntry("30 mins", TimeSpan.FromMinutes(30)));
            List.Add(
new DictionaryEntry("1 hours", TimeSpan.FromHours(1)));
            List.Add(
new DictionaryEntry("2 hours", TimeSpan.FromHours(2)));
            List.Add(
new DictionaryEntry("3 hours", TimeSpan.FromHours(3)));
            List.Add(
new DictionaryEntry("4 hours", TimeSpan.FromHours(4)));
            
try
            {
                cbSessionTimeOut.DataSource 
= List;
                cbSessionTimeOut.DisplayMember 
= "Key";
                cbSessionTimeOut.ValueMember 
= "Value";
            }
            
catch (Exception ce)
            {

                Console.WriteLine(ce.ToString()); ;
            }
        }

代码片段,关键:List添加的是要多个DictionaryEntry

posted @ 2010-10-21 12:06  Drek  阅读(1038)  评论(0编辑  收藏  举报