Combox simultaneously writes and obtains text and Value

Source: Internet
Author: User

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

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.