This project is read-only.

New Child in TreeView

Jun 6, 2011 at 2:20 PM

Hi, I'm trying to use the TreeViewFor to edit the details in a DetailFormFor, but when I add new items I get exceptions (in "jquery-1.6.1.min.js" or in "MVCControlToolkit.Controls-1.1.0.min.js") and sometimes it postback null to the tree items (m => m.Usuarios). If I edit or delete items it works. Can you help me?

                m => m.Usuarios,
                i => "items",
                "filetree treeview-black",
                new object[]
                    _S.L<ProjAprovTreeView>(h => h.DisplayFor(m => m.usuario_id).ToString())
                (x, y) => 0,
                "filetree treeview-black",
                new object[]
                    _S.L<ProjAprovTreeView>(h => string.Format(
                        "<div class='usuario' >{0} {1} {2}</div>", 
                        h.EditorFor(m => m.usuario_id).ToString(),
                        h.TreeViewAddButton(0, Url.Content("~/Content/themes/test/images/add.png"), 
                (x, y) => 0,
                (x) => "allnodes",
                (x, y) => TreeViewItemStatus.initializeShow,
                new TreeViewOptions() { 
                    Animated = 1,
                    Unique= false,
                    Opacity = 1,
                    CanMove = true,
                    CanAdd = true,
                    Persist = TreeViewPersistencyMode.EditOnly,
                    CookieId = "treeview"
                 m => m.Usuarios,
                 "Editar Usuários""TreeViewEdit",
My Class:
    public class ProjAprovTreeView
        public int usuario_id { getset; }
        public List<ProjAprovTreeView> items { getset; }
Jun 7, 2011 at 9:23 AM

I will try your code. Actually, we have modified template representation to work also with ajax just in the last releases(before you were not allowed to performs add in controls returned by ajax calls), however there might be some issues that still create problems. This means your code might be correct but there might be still a bug when using new item templates(that is addition of new items) in html returned by ajax calls. I'll let you know, and if there is a bug a will post a fix asap.

In the meantime I suggest you use razor helpers instead of lambda expressions to define the item templates if you use razor as view engine! they are easier to use, and you take more advantage of intellisense. LAmbda expressions templates are for the ones not using Razor.

Jun 7, 2011 at 11:50 AM

Thank you! I will try use Razor.

Jun 7, 2011 at 7:11 PM

hI Brunio,

As I already announced, actually the wrong behaviour you observed is due to a bug. We have already fixed it. 

I will be glad to you if you might try our fix on your code, so we will have a further test before preparing a bug fix release. You need just to substitute the main js file of the toolkit. 

If you would like to cooperate and test the fix on your cod, please send me a message on the contact form of my Blog, I will sent the js file in the reply to your message. Below the contact form of my blog:


Thanks in advance

Jun 10, 2011 at 6:30 PM


Now I'm with a new problem: how can I add items to a empty treeview? I have a treeview where Mode != null and Model.Count == 0.

See ya.

Jun 10, 2011 at 8:30 PM
Edited Jun 10, 2011 at 8:31 PM

YOU CANT! A grid with no rows is just an empty grid, but an empry tree is ....NOTHING.....a NULL pointer! :)

The grid is the container of its rows...but in the case of a tree each node is the container of its children, so: no nodes = no container at all = just a null pointer :)

You must have at least one root node. Just to make an example, consider the the tree of folders you have in an Email client....You can delete all nodes, but th initial root node that contains all folder CANNOT BE DELETED!


You can always add a ROOT node whose only purpose is that of OVERALL container. Consider that all nodes of a tree may be different datatypes, so you can define a root node that the user cannot delete and you can display it with an ad hoc template. You can also change the icon used to represent it b editing the ree css file and assing one more css rule just for the root node.

If you take the tree from a database, you don't need t store this root node in the databas, but you can add it after having retrieved all nodes from the database.


P.S. Nex time you would like to start a new discussion please ...just start a new discussion do not use an old discussion. Discussions we do here are useful also to other people that have similar problems, and the codeplex site has a search engine to find "discussions" related to a topic, so if you add a new topic to an old discussion will be difficult for someone else to find that topic. :)