Binding a treeview to a tree model

3 posts, 1 answers
  1. Andrea
    Andrea avatar
    52 posts
    Member since:
    Oct 2012

    Posted 15 Oct 2013 Link to this post

    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. Answer
    Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 17 Oct 2013 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andrea
    Andrea avatar
    52 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2013 Link to this post

    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.
Back to Top