下面的代码创建了一个类,它的实例将呈现记录。 此类声明了两个公共属性 (ID 和 Name) public class Record { int id; string name; public Record(int id, string name) { this.id = id; this.name = name; } public int ID { get { return id; } } public string Name { get { return name; } set { name = value; } } } 一旦声明了记录类,就可以创建它的实例的一个列表。 此列表将作为数据源。 在创建数据源之后,就可以使用编辑器的 DataBindings 属性把编辑器绑定到字段
ArrayList list = new ArrayList(); list.Add(new Record(1, "John")); list.Add(new Record(2, "Michael")); textEdit1.DataBindings.Add("EditValue", list, "Name", true);