在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
摘自msdn,详见http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/c7a82a6a-763e-424b-84e0-496caa9cfb4d/ public partial class Form1 : Form { // Content item for the combo box private class Item { public string Name; public int Value; public Item(string name, int value) { Name = name; Value = value; } public override string ToString() { // Generates the text shown in the combo box return Name; } } public Form1() { InitializeComponent(); // Put some stuff in the combo box comboBox1.Items.Add(new Item("Blue", 1)); comboBox1.Items.Add(new Item("Red", 2)); comboBox1.Items.Add(new Item("Nobugz", 666)); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { // Display the Value property Item itm = (Item)comboBox1.SelectedItem; Console.WriteLine("{0}, {1}", itm.Name, itm.Value); } } |
请发表评论