代码
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()); ;
}
}
{
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