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

How to Save and Retrive all the TreeView items

3 Answers 62 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
sri koch
Top achievements
Rank 1
sri koch asked on 10 Mar 2010, 08:10 AM
Hi Folks,
   just started to work on RadTreeView, and i'm going good so far but i stuck up with one thing, first let me make u clear why and what i'm doing with this treeview
1. I defined my simple treeview with only one Node in it in XAML
2. I'm adding some new nodes(Parents,childs,siblings,etc...) to the treeview with one node.
3.Tree Structure remains same till i don't jump from that page but if i just refresh or go to some new page and come back my treeview displays only that one node that was defined in my XAML code
4.All i need is i want to store the whole structure of the treeview(With newly added items) so that i can update it to DB and also can able to retrieve it with out loosing any nodes/items in the tree view.

all i need is i need to store all the nodes from the treeview to the database and also should be able to retrieve them.



3 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 11 Mar 2010, 03:46 PM
Hello sri koch,

Generally you would want to use a web service via which you can get and store the data you display in your UI. Using web services is not specific to RadControls for Silverlight, so below I am pasting two links you might find useful:

http://silverlight.net/learn/quickstarts/webservices/
http://visualstudiomagazine.com/Articles/2009/06/22/Consuming-WCF-Services-in-Silverlight-3.aspx

All the best,
Tihomir Petkov
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
sri koch
Top achievements
Rank 1
answered on 12 Mar 2010, 06:50 PM
Hi Tihomir Petkov ,
   Thanks for your links but for me using a web service / wcf service is not a problem all i need is how can i get the whole treeviewitems in Rad TreeView even if i add some nodes dynamically from code behind. I'm even able to add the nodes to TreeView but i'm unable to read the treeview items and also want to store them in a collection or some thing like stuff which i can save the structure and display after i login into the system.

<telerikNavigation:RadTreeView x:Name="TreeView1" Margin="8,8,120,8" Grid.Row="1"  ExpanderStyle="{StaticResource ExpanderStyle}" SelectionChanged="TreeView1_SelectionChanged">
            <telerikNavigation:RadTreeViewItem Header="MyWorkspace" IsEditable="True">
                <telerikNavigation:RadTreeViewItem Header="MyDocuments">
                    <telerikNavigation:RadTreeViewItem Header="Document1"/>
                    <telerikNavigation:RadTreeViewItem Header="Document2"/>
                    <telerikNavigation:RadTreeViewItem Header="Document3"/>
                </telerikNavigation:RadTreeViewItem>
                <telerikNavigation:RadTreeViewItem Header="MyPortfolios">
                    <telerikNavigation:RadTreeViewItem Header="Portfolio1"/>
                    <telerikNavigation:RadTreeViewItem Header="Portfolio2"/>
                    <telerikNavigation:RadTreeViewItem Header="Portfolio3"/>
                </telerikNavigation:RadTreeViewItem>
            </telerikNavigation:RadTreeViewItem>
        </telerikNavigation:RadTreeView>

so now if i add a new node to my current tree from Code Behind where my Header is a string returned by a web service

            RadTreeViewItem tvi = new RadTreeViewItem();
            tvi.Header = e.Result.ToString();          
            RadTreeViewItem rtvi = TreeView1.SelectedItem as RadTreeViewItem;
            rtvi.Items.Add(tvi);

so now after adding this node i want to save the whole TreeView structure along with the items defined in the XAML and also the new Node which got added to TreeView from code behind. After saving the whole TreeViewstructure to database i should be able to retrieve it from a webservice / wcf .

I hope you got my point for which i'm looking for.





0
Tihomir Petkov
Telerik team
answered on 17 Mar 2010, 03:50 PM
Hi sri,

Depending on the exact business objects you work with, it will make sense to store only the unique and relevant data. E.g. if the only useful information you render in the TreeView are the strings in the item headers, then it would be most efficient to store in your DB business objects similar to the mock one below (assuming you would want to also store whether an item is expanded or not):

public class DataItem
{
    public DataItem()
    {
        this.Items = new List<DataItem>();
    }

    public string Header { get; set; }
    public bool IsExpanded { get; set; }
    public List<DataItem> Items { get; set; }
}


Using the appropriate DataTemplates and a ContainerBinding, you should be able to easily render your data in the TreeView by binding it to a collection of the above objects and later on storing that source collection back to your database.

Kind regards,
Tihomir Petkov
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.
Tags
TreeView
Asked by
sri koch
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
sri koch
Top achievements
Rank 1
Share this question
or