The Devexpress TreeList control is bound to display the parent-child node image and devexpresstreelist.

Source: Internet
Author: User

The Devexpress TreeList control is bound to display the parent-child node image and devexpresstreelist.

Today, a colleague consulted the Devexpress TreeList control to automatically display the parent-child node image. However, the result does not show the parent-child node relationship, but shows all nodes as parent nodes, the code for the image class is as follows:

 public class Item:XPBaseObject
 {
 public Item()
            : base()
        {
        }

        public Item(Session session)
            : base(session)
        {
        }

         [Key(true)]
        public int Id{ get;set; }
    

    public string Name{get;set;}


        [Association("SubItems"),Persistent("ParentId")]
        public Item ParentItem;

     [Association("SubItems", typeof(Item)), Aggregated]
        public XPCollection<Item> SubItems
        {
            get { return GetCollection<Item>("SubItems"); }
        }
    
}    

 

1 // ... omitted
2 
3 this.treeList1.KeyFieldName = "Id";
4 this.treeList1.Name = "treeList1";
5 this.treeList1.ParentFieldName = "ParentId";
6
7 // ... omitted

 

The actual data structure automatically generated by XPO in the database also meets our design requirements. The entered data is correct, but the result is not displayed based on the parent-child node relationship. Finally, find the difference in the previous code, that is, this. treeList1.ParentFieldName = "ParentId"; the field name is not declared in the object class, although the field name ParentId is specified in the property ParentItem, it is only used to store the foreign key relationship to the field ParentId. The TreeList control does not intelligently read this value as the primary key value of the parent node. You must declare a read-only ParentId attribute in the object class to solve this problem. See the following code:

1 public class Item: XPBaseObject
  2  {
  3
  4 // ... omitted
  5
  6
  7 [NonPersistent]
  8 public int ParentId
  9        {
10 get {return ParentItem == null? 0: this.ParentItem.Id;}
11}
12
13
14 // ... omitted
15
16
17} 

 

Summary: The fields bound to the TreeList control can be bound only when the attributes of the object class exist, if the attribute does not exist, you can write a read-only file that does not need to be stored in the database for private binding.

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.