This is a migrated thread and some comments may be shown as answers.

[Solved] Bind at arbitrary levels

2 Answers 92 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris Williams
Top achievements
Rank 1
Chris Williams asked on 28 Oct 2010, 10:47 PM
I was wondering whether there was any possiblity to mix declared TreeView items and bound items.

For example, let's say that I wanted to create a mvc treeview that had the word "Trees" as the single top node, and then a list of Tree types underneath it, as such:

Trees
    -> Ash
    -> Maple
    -> Oak

I have a model of IQueryable<Tree>, and I can create a flat treeview fine. But, what I want to do is manually create a single Item at the root ("Trees"), and then bind my model as its children.

Any suggestions as to how I might do that?

2 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 29 Oct 2010, 03:26 PM
Hello Chris,

Luckily, the TreeViewItem is a NavigationItemContainer, so:

.Items(treeview => {
    treeview.Add().Text("Employees")
        .ToItem()
        .BindTo(Model, mappings =>

        {
            mappings.For<Employee>(binding => binding
                .ItemDataBound((item, employee) =>
                {
                    item.Text = employee.FirstName;
                })
                .Children(employee => employee.Employees));
        });
})


Hope this helps,
Alex Gyoshev
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
Chris Williams
Top achievements
Rank 1
answered on 29 Oct 2010, 08:15 PM
Thanks, this works beautifully.
Tags
TreeView
Asked by
Chris Williams
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Chris Williams
Top achievements
Rank 1
Share this question
or