How to bind keyvaluepair data to the ComboBox control

Source: Internet
Author: User

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 ";
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.