⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combox&listbox(列表框绑定).txt

📁 C# 是创新性的新式编程语言
💻 TXT
字号:
//通过设置DataSource,DisplayMember,ValueMember属性绑定,只读的。

	public class Form1 : System.Windows.Forms.Form
	{
ArrayList al=new ArrayList();
		private void Form1_Load(object sender, System.EventArgs e)
		{
			
			
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			al.Add(new Person("China",0));
			al.Add(new Person("USA",1));
			al.Add(new Person("Japan",2));
			this.comboBox1.DataSource=al;
			this.comboBox1.DisplayMember="Country";
			this.comboBox1.ValueMember="Code";
		}

		private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			 //this.label2.Text=((Person)comboBox1.SelectedItem).Country;
			this.label2.Text=comboBox1.Text.ToString();
		}

}

public class Person
	{
		private string country=string.Empty;
		public string Country
		{
			get{return country;}
			set{country=value;}
		}
		private int code=0;
		public int Code
		{
			get{return code;}
			set{code=value;}
		}
		public Person(string country,int code)
		{
			this.country=country;
			this.code=code;
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -