日期:2014-05-17 浏览次数:21002 次
public partial class Work
{
public int? Id { get; set; }
public string Name { get; set; }
}
public partial class Works
{
private static List<Work> works = new List<Work>();
public static List<Work> GetWorks
{
get
{
works.Clear();
works.Add(new Work() { Id = 1, Name = "程序员"});
works.Add(new Work() { Id = 2, Name = "项目经理" });
works.Add(new Work() { Id = 3, Name = "技术总监" });
return works;
}
}
}
private void Form2_Load(object sender, EventArgs e)
{
this.listBox1.DataSource = Works.GetWorks;
this.listBox1.DisplayMember = "Name";
this.listBox1.ValueMember = "Id";
}
private void button1_Click(object sender, EventArgs e)
{
this.listBox1.DisplayMember = "Id";
}