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.