C # winform Tip 2: manually bind data to ComboBox

Source: Internet
Author: User
Defines a class and has two attributes. ///   <Summary>
/// Metadata
///   </Summary>
[System. Diagnostics. debuggerstepthrough]
[Serializable]
Public Class Sanddata
{
String key = "" ;
Object value = "" ;
///   <Summary>
/// Metadata
///   </Summary>
Public Sanddata (){}
///   <Summary>
/// Metadata
///   </Summary>
Public Sanddata (string m_key, object m_value ){
This . Key = m_key;
This . Value = m_value;
}
Public String key
{
Get { Return Key ;}
Set {Key = value ;}
}
Public Object Value
{
Get { Return This . Value ;}
Set { This . Value = value ;}
}

}

Then, use

Arraylist list = New Arraylist ();
Foreach (Datarow row In Table. Rows)
{
String TEXT = row [ " D_name " ]. Tostring () + " [ " + Row [ " Uptownname " ]. Tostring () + row [ " Buildingname " ]. Tostring () + row [ " Unitname " ]. Tostring () + " ] " ;
String Value = row [ " ID " ]. Tostring ();

Sanddata Vo = New Sanddata ();
VO. Key = text;
VO. value = value;
List. Add (VO );
}
This . Combobox1.datasource = List;
This . Combobox1.displaymember = " Key " ;
This . Combobox1.valuemember = " Value " ;

In this way, the value of CBB. selectedvalue is obtained.

 

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.