Lisa
Lisa

Reputation: 3181

Multi level treeView

I'm working on binding three levels to my telerik treeView

+Directories 

  *Archives

     -Documents

  *Directories

This is my code:

 <% Html.Telerik().TreeView()
           .Name("TeleTreeView")
           .DragAndDrop(true)
           .ExpandAll(true)
            .BindTo(Model, mappings =>
              {
                  mappings.For<SARS.Directory>(binding => binding
                          .ItemDataBound((item, directory) =>
                          {
                              item.Text = (string)directory.DirectoryName;
                              item.Value = (string)directory.NodeID;
                              item.ImagUrl="~/Images/Folder-Add-icon.png";
                          })


                          //Sub Directories
                          .Children(directory => directory.Directory1));
                          mappings.For<SARS.Directory>(binding => binding
                          .ItemDataBound((item, dir) =>
                          {
                              item.Text = dir.DirectoryName;
                              item.Value = (string)dir.NodeID;
                              item.ImagUrl="~/Images/Folder-Add-icon.png";
                          })

                          //Sub archives
                            .Children(directory => directory.Archives));
                            mappings.For<SARS.Archive>(binding => binding
                            .ItemDataBound((item, arch) =>
                            {
                                item.Text = arch.ArchiveName;
                             }));

        })
              .Render();%>

Edit:The problem is that I'm not getting the Archives level. What should I do?

Upvotes: 0

Views: 1670

Answers (3)

chris
chris

Reputation: 111

I recently had the same problem whereby some nodes children would be of a different and/or mixed type:

 - TypeA
     - TypeA
           - TypeA + TypeB
           - TypeB

The way I resolved this was to simply introduce an interface on the various types and then bind the treeview to the interface:

public interface ITreeNode
{
    int Id { get; }
    string Name { get; }
    IEnumerable<ITreeNode> ChildrenNodes { get; }
}


Html.Kendo().TreeView()
    .BindTo(Model.CurrentHierarchy, mappings => 
    {
        mappings.For<ITreeNode>(binding => binding.ItemDataBound((item, node) =>
        {
           item.Id = node.Id.ToString();
           item.Text = node.Name;                
        })
        .Children(o => o.ChildrenNodes))
     });

Upvotes: 0

Suvodeep Das
Suvodeep Das

Reputation: 33

Directory1 should contains a Iennumerable list of a class like Archives , then its easy to get the child nodes . I have tried upto 4 levels of hierarchy.

Upvotes: 1

Atanas Korchev
Atanas Korchev

Reputation: 30671

This is not currently supported. You cannot specify children of different type. The second call to Children() will overwrite the previous one.

Upvotes: 0

Related Questions