C # ComboBox

Source: Internet
Author: User

Employee

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceWinapp03_combobox8 {9     enumem_departmentTen     { One Development Department, A Personnel Department, - Finance Department -     } the     classEmployee -     { -          Public intID {Get;Set; } -          Public stringName {Get;Set; } +          PublicEm_department Department {Get;Set; } -          PublicDateTime BirthDate {Get;Set; } +  A         /// <summary> at         ///overriding the ToString () method -         /// </summary> -         /// <returns>return Value: Name property</returns> -          Public Override stringToString () -         { -             return  This. Name; in         } -     } to}

From1

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten  One namespaceWinapp03_combobox A { -      Public Partial classForm1:form -     { the          PublicForm1 () -         { - InitializeComponent (); -         } +  -         Private voidForm1_Load (Objectsender, EventArgs e) +         { A             /**        at //Add a string to ComboBox1 - comboBox1.Items.Add ("Hello"); - ComboBox1.Items.Add ("World"); - comboBox1.Items.Add ("Hello, World"); - //Set default index - Combobox1.selectedindex = 2;  in              * */ -  toList<employee> employees =NewList<employee>() +             { -                 NewEmployee () {ID =1, Name ="Zhang San", BirthDate =NewDateTime (1988,Geneva, at), Department =em_department. Development department}, the                 NewEmployee () {ID =2, Name ="John Doe", BirthDate =NewDateTime (1990,Ten, ,), Department =em_department. Finance Department}, *                 NewEmployee () {ID =3, Name ="Harry", BirthDate =NewDateTime (1995,Geneva, .), Department =em_department. Personnel Department}, $                 NewEmployee () {ID =4, Name ="Zhao Liu", BirthDate =NewDateTime (1990, -, the), Department =em_department. Development Department}Panax Notoginseng             }; -  the             //Binding Data Sources +Combobox1.datasource =employees; A             //The Name property of the data source is displayed theCombobox1.displaymember ="Name"; +             //The Value field is the ID property of the data source -Combobox1.valuemember ="ID"; $             //Set index, default not selected ( -1) $Combobox1.selectedindex =-1; -         } -  the         Private voidCombobox1_selectedvaluechanged (Objectsender, EventArgs e) -         {Wuyi             if( -1==Combobox1.selectedindex) the             { -Label1. Text ="index of the currently selected item: 1"; WuLabel2. Text ="no items are currently selected"; -Label3. Text ="no items are currently selected"; About             } $Label1. Text ="index of the currently selected item:"+comboBox1.SelectedIndex.ToString (); -Label2. Text ="currently checked item ID:"+comboBox1.SelectedValue.ToString (); -Label3. Text ="the currently selected name:"+comboBox1.SelectedItem.ToString (); -         } A  +     } the}

C # ComboBox

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.