Mohit Deshpande
Mohit Deshpande

Reputation: 55227

Recursively retrieving all items in a TreeViewItem

I have a RadTreeView (Telerik's version of a TreeView) that has the following hierarchical order:

<navigation:RadTreeView ImagesBaseDir="/Images/" x:Name="rtvLibrary" Margin="8" Grid.Row="0">
            <navigation:RadTreeViewItem DefaultImageSrc="Home.png" Header="Home" IsExpanded="True">
                <navigation:RadTreeViewItem DefaultImageSrc="Todo.png" Header="Tasks" />
                <navigation:RadTreeViewItem DefaultImageSrc="Flag.png" Header="Flagged" />
                <navigation:RadTreeViewItem DefaultImageSrc="Completed.png" Header="Completed" />
                <navigation:RadTreeViewItem DefaultImageSrc="Courses.png" Header="Courses">
                    <navigation:RadTreeViewItem DefaultImageSrc="Folder.png" Header="Winter 2010">
                        <navigation:RadTreeViewItem DefaultImageSrc="Course.png" Header="Health" />
                    </navigation:RadTreeViewItem>
                </navigation:RadTreeViewItem>
            </navigation:RadTreeViewItem>
        </navigation:RadTreeView>

And inside the RadTreeViewItem with the Header of Courses, I will allow users to make many folders and courses (RadTreeViewItems). So how can I iterate though all the RadTreeViewItems within the RadTreeViewItem with the Header of Courses?

Upvotes: 0

Views: 982

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292465

So how can I iterate though all the RadTreeViewItems

Don't do it this way ; bind your TreeView to a collection instead. That way you won't have to manipulate UI components to access the data, you will access the data directly. By keeping a good separation of UI and data, your code will be much easier to maintain, to test and to reuse

Upvotes: 1

Related Questions