How do you code the Infragistics tree for unlimited levels of hierarchy? I.e. sub-nodes under sub-nodes under sub-nodes, etc.
Desired result:
Main node 1
- Sub node 1
- Sub node 2
- Sub-sub node 1
- Sub-sub-sub node
- Sub node 3, etc.
Here is my model class. Notice the "ChildItems" list inside it.
public class TreeListItem : ICloneable, IComparable, IComparable<TreeListItem> { public string Text { get; set; } public object Value { get; set; } public string Base64ImageUrl { get; set; } = ""; public List<TreeListItem> ChildItems = new List<TreeListItem>();}
Here is my MVC view code, which only shows the first level without any child items.
@(Html.Infragistics().Tree() .ID("FilterTree") .Bindings(b1 => { b1 .ValueKey("Value") .TextKey("Text") .ImageUrlKey("Base64ImageUrl") .ChildDataProperty("ChildItems"); }) .DataSource(Model.TreeListItems) .DataBind() .Render())
This also did not show any child items:
@(Html.Infragistics().Tree() .ID("FilterTree") .Bindings(b1 => { b1 .ValueKey("Value") .TextKey("Text") .ImageUrlKey("Base64ImageUrl") .ChildDataProperty("ChildItems") .Bindings(b2 => b2 .ValueKey("Value") .TextKey("Text") .ImageUrlKey("Base64ImageUrl") .ChildDataProperty("ChildItems") ); }) .DataSource(Model.TreeListItems) .DataBind() .Render())
Hello Ray,
I am glad that the issue has been resolved.
Thank you for choosing Infragistics components!
RegardsViktor KombovEntry Level Software DeveloperInfragistics, Inc.
I answered my own question moments after posting!
My problem was the ChildItems property in the TreeListItem class. It needed to be structured like this below. Adding { get; set; } to the ChildItems property fix it. Oops!
public List<TreeListItem> ChildItems { get; set; } = new List<TreeListItem>();