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

Binding a treeview to a tree model

2 Answers 148 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Andrea
Top achievements
Rank 1
Andrea asked on 15 Oct 2013, 10:59 AM
Hello, i have a tree data structure like the following:

public class MyTreeNode
{
    public string Display{get;set;}
    public List<MyTreeNode> childs {get;set;}
}

how can I bind to this datastructure?

Using your WPF Treeview I was able to do using the following code (data context is a root node that is not displayed)

<TreeView  Name="treeView1" ItemsSource="{Binding Childs}">
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding Childs}">
            <StackPanel Orientation="Horizontal" Height="18">
                <TextBlock Text="{Binding Display}" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

I do not understand how to do with winforms version of treeview control.

Can anybody please help?

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 17 Oct 2013, 04:09 PM
Hello Andrea,

Thank you for writing.

In this case you can set the DisplayMember and ChildMember properties like this:
this.radTreeView1.DisplayMember = "Display\\Display";
this.radTreeView1.ChildMember = "MyTreeNode\\childs";

Also in the following topics you can find detailed information about tree view data binding:

I hope this information helps. Should you have any other questions, I will be glad to assist you.

Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Andrea
Top achievements
Rank 1
answered on 23 Oct 2013, 03:50 PM
Thanks for the answer i did not had a chance to test because i've switched to event driven load on demand, but that's good to know.

Best regards.
Tags
Treeview
Asked by
Andrea
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Andrea
Top achievements
Rank 1
Share this question
or