C # combox write and obtain both text and Value
2007-10-10 16:33:44| Category: C # knowledge|Report|Font SizeSubscription
Public class comboboxitem // create a class storage value
{
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;
}
}
Private void form1_load (Object sender, eventargs E)
{
// Store text and Value
Int Ss = 0;
For (INT I = 0; I <10; I ++)
{
Comboboxitem newitem = new comboboxitem ();
Newitem. Text = I. tostring ();
Ss = I + 100;
Newitem. value = ss. tostring ();
Combobox1.items. Add (newitem );
}
}
Private void combobox#selectedindexchanged (Object sender, eventargs E)
{
// Display the value of the selected combox in textbox
Textbox1.text = (comboboxitem) combobox1.items [combobox1.selectedindex]). value. tostring ();
}
Combox simultaneously writes and obtains text and Value