ComboBox Data Binding skills

Source: Internet
Author: User
A common binding of ComboBox is to bind a dataset to it. But if you bind an ilist to it, you have a skill.
If your ilist is list <idictionary>, it won't work. The displaymember and valuemember of ComboBox need to get the value from the object's property, while the idictionary is only the key, so it won't work. If you want to bind ilist or arraylist, you have to use an entity class (concept in Java or ORM) as the object for storing data, and then add the object to the list, then you can assign a value to datasource. Defines a class and has two attributes.
Public class valueobject {
Private string _ name;
Private string _ value;
Internal name
{
Get {return _ value ;}
Set {_ value = value ;}
}
}

Then, use
Arraylist list = new arraylist ();
For (INT I = 0; I <3; I ++)
{
Valueobject Vo = new valueobject ();
VO. Name = "";
VO. value = "1 ";
List. Add (VO );
}

ComboBox CBB = new ComboBox ();
CBB. datasource = List;
CBB. displaymember = "name ";
CBB. valuemember = "value ";

In this way, the value of CBB. selectedvalue is obtained.
If Java is used, the role of VO will be clear.

In addition, many people do not know how to select a list based on the read value.
ComboBox. selectedvalue = "XXX" can be selected.
The following is a stupid method. I found that ienumerator enumer = org_type_id.items.getenumerator () was used before this method ();
Int I = 0;
Enumer. Reset ();
While (enumer. movenext ())
{
Datarowview dt = (datarowview) enumer. Current;
If (dt ["org_type_id"]. tostring (). Equals (DRV ["org_type_id"]. tostring ()))
{
Org_type_id.selectedindex = I;
}
I ++;
}

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.