Http://blog.163.com/prince.king_521/blog/static/1068912042010101051555903/
Directly run the code. Data of the keyvaluepair <byte, string> type is bound to the ComboBox control, and displaymember and valuemember of the ComboBox can be specified.
The Code is as follows:
/// <Summary>
/// Obtain the data source
/// </Summary>
/// <Returns> </returns>
Private list <keyvaluepair <byte, string> getdata ()
{
List <keyvaluepair <byte, string> List = new list <keyvaluepair <byte, string> ();
For (INT I = 0; I <5; I ++)
{
Keyvaluepair <byte, string> item = new keyvaluepair <byte, string> (byte) I, "test" + I. tostring ());
List. Add (item );
}
Return list;
}
/// <Summary>
/// Bind the list data to ComboBox
/// </Summary>
Private void binddata ()
{
ComboBox cmbtest = new ComboBox ();
// Obtain the system sound information and bind it to the drop-down control
List <keyvaluepair <byte, string> List = getdata ();
Cmbtest. datasource = List;
Cmbtest. displaymember = "value ";
Cmbtest. valuemember = "key ";
}