您好,具体用法请参照
- private void Form1_Load(object sender, EventArgs e)
- {
- // create a list
- List<Products> product = new List<Products>();
- // add the objects to the list
- product.Add(new Products(567, "Bicycle", 5));
- product.Add(new Products(456, "Car", 5000));
- product.Add(new Products(789, "Bike", 1500));
- // bind TreeView to the list
- c1TreeView1.BindingInfo.DataSource = product;
- // set the field to be displayed in the column
- c1TreeView1.Columns[0].DisplayFieldName = "Description";
- c1TreeView1.Columns[1].DisplayFieldName = "Price";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- C1.Win.TreeView.C1TreeNode lv1Node = new C1.Win.TreeView.C1TreeNode();
- c1TreeView1.Nodes.Add(lv1Node);
- Products pd = new Products(729, "MOTO", 500);
- lv1Node.SetValue(pd, 0);
- lv1Node.SetValue(799, 1);
- }
- }
- public class Products
- {
- private int _id;
- private string _description;
- private float _price;
- public int ID
- {
- get { return _id; }
- set { _id = value; }
- }
- public string Description
- {
- get { return _description; }
- set { _description = value; }
- }
- public float Price
- {
- get { return _price; }
- set { _price = value; }
- }
- public Products(int id, string description, float price)
- {
- _id = id;
- _description = description;
- _price = price;
- }
- }
复制代码
编辑多列 需要是绑定了数据集合而且DisplayFieldName 要有值,才可以进行。 |