This question is locked. New answers and comments are not allowed.
Hi!
Is it possible to generate TreeView recursively? I have items n amount both horizontally and vertically. All the examples I have seen have only 1 or 2 levels.
I have following structure:
{Main level item #1}
{Depth 1.. Child item #1}
{Depth n.. Child item #1}
{Depth n.. Child item #n}
....
{Depth 1.. Child item #n}
....
{Main level item #n}
-Tatu
Is it possible to generate TreeView recursively? I have items n amount both horizontally and vertically. All the examples I have seen have only 1 or 2 levels.
I have following structure:
{Main level item #1}
{Depth 1.. Child item #1}
{Depth n.. Child item #1}
{Depth n.. Child item #n}
....
{Depth 1.. Child item #n}
....
{Main level item #n}
-Tatu
4 Answers, 1 is accepted
0
Hi Tx3,
What is the class which you are trying to bind the TreeView to? Pasting it here would help us provide specific directions.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
What is the class which you are trying to bind the TreeView to? Pasting it here would help us provide specific directions.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tx3
Top achievements
Rank 1
answered on 11 May 2010, 07:22 AM
Sure, here are my classes.
Small explanation: The first level is called ProductBranch and under those there are x amount of ProductVersionLeaf instances in the List. Each of ProductVersionLeaf instances can have x amount of ProductVersionLeaf instances and so on..
| public class ProductViewModel |
| { |
| public class ProductVersionLeaf : BaseTreeViewItem |
| { |
| public string Version { get; set; } |
| public string StatusText { get; set; } |
| public Common.Enums.Status Status { get; set; } |
| public string Label { get; set; } |
| public Guid ProductId { get; set; } |
| public bool IsLast { get; set; } |
| public List<ProductVersionLeaf> SubProductVersions = new List<ProductVersionLeaf>(); |
| public ProductVersionLeaf() |
| { |
| this.SubProductVersions = new List<ProductVersionLeaf>(); |
| } |
| } |
| public class ProductBranch : BaseTreeViewItem |
| { |
| public List<ProductVersionLeaf> ProductVersions = new List<ProductVersionLeaf>(); |
| public ProductBranch() |
| { |
| this.ProductVersions = new List<ProductVersionLeaf>(); |
| } |
| } |
| public List<ProductBranch> Products = new List<ProductBranch>(); |
| public ProductViewModel() |
| { |
| this.Products = new List<ProductBranch>(); |
| } |
| } |
If my data structure is not suitable then I can change it if something else has better support in the TreeView.
0
Hi Tx3,
I think the binding to model example will help you. You need to modify the sample code to create mappings for your types (ProductVersionLeaf and ProductBranch).
Best wishes,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I think the binding to model example will help you. You need to modify the sample code to create mappings for your types (ProductVersionLeaf and ProductBranch).
Best wishes,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tx3
Top achievements
Rank 1
answered on 11 May 2010, 08:37 AM
I think was missing that last .Children call. Here is the working code for my application. In the example TreeView has only main level (for example Beverages) and children (like Chai), so there is no need for the Children.
Atanas, thank you for guiding me to the correct direction!
| <%= Html.Telerik().TreeView() |
| .Name("TreeView") |
| .BindTo(Model.Products, mappings => |
| { |
| // product level |
| mappings.For<ProductViewModel.ProductBranch>(binding => binding |
| .ItemDataBound((item, product) => |
| { |
| item.Selected = product.IsSelected; |
| item.Expanded = product.IsExpanded; |
| item.Encoded = false; |
| item.Text = ProductHelper.GetProductContent(product); |
| }) |
| .Children(product => product.ProductVersions)); |
| // product version |
| mappings.For<ProductViewModel.ProductVersionLeaf>(binding => binding |
| .ItemDataBound((item, productVersion) => |
| { |
| item.Selected = productVersion.IsSelected; |
| item.Encoded = false; |
| item.Text = ProductHelper.GetProductVersionContent(productVersion, Request.Url.PathAndQuery); |
| }) |
| .Children(productVersion => productVersion.SubProductVersions)); |
| }).HtmlAttributes(new { id = "myGridControl" })%> |
-Tatu