How can I set text and value without binding ComboBox?

Source: Internet
Author: User
Reprinted from: http://www.21ds.net/article/21/26299

In winform, ComboBox is compared with dropdownlist in web control, so I never know what value is in ComboBox? Valuemember can only be used for binding, while selectedvalue can only take the value bound from the database. I can only define one class to implement the manual addition of ComboBox item

Public class comboboxitem
{
Private string _ text = NULL;
Private object _ value = NULL;
Public String text {get {return this. _ text;} set {This. _ text = value ;}}
Public object value {get {return this. _ value;} set {This. _ value = value ;}}
Public override string tostring ()
{
Return this. _ text;
}
}
This sectionCodeI found it from the Internet and then used
Comboboxitem newitem = new comboboxitem ();
Newitem. Text = "ABC ";
Newitem. value = "1 ";
Combobox1.items. Add (newitem );

When I set the value, I didn't notice that selectedvalue was taken from valuemember, so I forgot to forcibly convert the type and wasted an hour ..

Usage:
Comboboxitem myitem = (comboboxitem) combobox1.items [0];
String strvalue = myitem. value;

In fact, many parts are different from those of webform, so they are still in the exploratory stage.

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.