实体类
public class TreeListTest
{
public int ID { get; set; }
public int PARENTID { get; set; }
public string NAME { get; set; }
}
实例化数据
List<TreeListTest> list = new List<TreeListTest>();
list.Add(new TreeListTest {
ID=1,
PARENTID=1,
NAME="宝马"
});
list.Add(new TreeListTest
{
ID = 2,
PARENTID = 1,
NAME = "宝马x5"
});
list.Add(new TreeListTest
{
ID = 3,
PARENTID = 3,
NAME = "奔驰"
});
list.Add(new TreeListTest
{
ID = 4,
PARENTID = 3,
NAME = "奔驰c200"
});
this.treeList1.DataSource = list;
this.treeList1.KeyFieldName = "ID";
this.treeList1.ParentFieldName = "PARENTID";
this.treeList1.Columns[0].Caption = "测试";