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

Populate TreeView using WebService

20 Answers 439 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Meerkat
Top achievements
Rank 1
Meerkat asked on 15 Aug 2008, 02:00 PM

Hello,
I am afraid I am back again.
I am going to ask one final question before I am forced to consider going elsewhere.

I am sure your TreeView is great but I cannot wait for the documentation to come out next year. All the available examples seem to be just for show. I cannot find any examples anywhere ( believe me, this time I tried hard) that show how to use it in realistic scenario. Few people type in nodes by hand: most get the information from a webservice. ( Your examples that use XML files don't work as they stand using Silverlight: the XML file has to be obtained using a webservice or similar) 
I KNOW lots of your potential users would really appreciate a working example of how to do this.
I realise it is a lot of trouble but it would be SO useful. I notice that others have asked you for the same thing and have been ignored. It would be great if the same does not happen again because this is really important.

Crossing my fingers.

Regards,
Pete

20 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 18 Aug 2008, 07:33 AM
Hello Pete,

Thank you for the feedback on the documentation!

We know that this is very important and I can assure you that we will have a first class documentation available with our Silverlight suite. We are now working extensively on this part of the product and we will release our first version of the Help files together with the SP1 that is coming at the end of this month.

As for the question - basically the way the RadTreeView is consuming the xml data is not dependant from where this data is coming - it doesn't matter if the xml file is from your local system or if it is coming from a web service - the binding is the same.

In order to help you with your scenario - what kind of web service you want to use? Astoria, WCF, or something else?


Regards,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meerkat
Top achievements
Rank 1
answered on 18 Aug 2008, 10:09 AM

Good Morning Valentin,

Thank you very much for your calm and reasonable reply.

I realise I am being unresonable by asking you more than I have a right to. However the more time I spend trying to work this out, the more frustrated I get - sorry!

I understand you have many other things to do, but if you could use the following to display a tree, I would be extremely grateful. (as I am sure will quite a few others)


------------------------
SCENARIO ONE
------------------------
This is a XML file I am trying to display in your tree. It is called genericXML.

<?

xml version="1.0" encoding="UTF-8"?>
<
Items>
    <
XmlNodeItem Header="Animal">
        <
Items>
            <
XmlNodeItem Header="Dog" />
            <
XmlNodeItem Header="Cat" />
        </
Items>
    </
XmlNodeItem>
    <
XmlNodeItem Header="Fish">
        <
Items>
            <
XmlNodeItem Header="Fresh Water">
                <
Items>
                    <
XmlNodeItem Header="Roach"/>
                    <
XmlNodeItem Header="Bream"/>
                </
Items>
            </
XmlNodeItem>
            <
XmlNodeItem Header="Salt Water">
                <
Items>
                    <
XmlNodeItem Header="Edible"/>
                    <
XmlNodeItem Header="Flat">
                        <
Items>
                            <
XmlNodeItem Header="Skate"/>
                            <
XmlNodeItem Header="Sole"/>
                        </
Items>
                    </
XmlNodeItem>
                </
Items>
            </
XmlNodeItem>
        </
Items>
    </
XmlNodeItem>
</
Items>

Th following retrieves this XML file from the server. Could you please demonstrate how to display it using your RadTreeView.

  public MyTestTree()

    {

      InitializeComponent();

      LoadXMLFile();

    }

    private void LoadXMLFile()

    {

      WebClient xmlClient = new WebClient();

      xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);

      xmlClient.DownloadStringAsync(new Uri("genericXML.xml", UriKind.RelativeOrAbsolute));

    }

    void XMLFileLoaded(object sender, DownloadStringCompletedEventArgs e)

    {

//The content of this procedure is proably complete rubbish but I include it anyway.

      if (e.Error == null)

      {

        string xmlData = e.Result;

        XDocument xmlItems = XDocument.Parse(xmlData);

        var items = from item in xmlItems.Descendants("Items")

                    select item;

        myTree.ItemsSource = items.ToList();

      }

    }

------------------------
SCENARIO TWO
------------------------
The following is the contents of an SQL Server table called TreeNoText

NodeID ParentID NodeText
       0                    0             Cars
       1                    0             Notes
       2                    0             Big
       3                    2             Cadillac
       4                    2             Humvee
       5                    0             Small
       6                    5             Clio
       7                    5             Punto
       8                    0             Animals
       9                    8             Mammals
     10                    9             Land
     11                  10             Horse
     12                  10             Rabbit
     13                  12             Floppy Eared
     14                    9             Sea
     15                  14             Whale
     16                    8             Reptiles
     17                  16             Crocodile
     18                  16             Alligator

The following code retrieves the TreeNoText table (using ADO.NET Data Services) and displays it in a standard MS grid. It would be outstanding if you could also demonstrate how to display this in a RADTreeView.

    public Page()

    {

      InitializeComponent();

      Loaded += new RoutedEventHandler(Page_Loaded);

    }

    void Page_Loaded(object sender, RoutedEventArgs e)

    {

      Uri ServiceAddress = new Uri(Application.Current.Host.Source, "../ADONetService.svc");

      Broadgate_DataEntities proxy;

      proxy = new Broadgate_DataEntities(ServiceAddress);

      DataServiceQuery<TreeNoText> query =

        (DataServiceQuery<TreeNoText>)(from c in proxy.TreeNoText

                                       where c.PropertyNumber == "00003"

                                       select c);

        query.BeginExecute(TreeNoTextCallback, query);

    }

    private void TreeNoTextCallback(IAsyncResult iar)

    {

      ObservableCollection<TreeNoText> listTreeNoText = new ObservableCollection<TreeNoText>();

      DataServiceQuery<TreeNoText> query = (DataServiceQuery<TreeNoText>)iar.AsyncState;

      IEnumerable<TreeNoText> results = query.EndExecute(iar);

      listTreeNoText = new ObservableCollection<TreeNoText>();

    

      foreach (var item in results)

      {

        listTreeNoText.Add(item);

      }

      myDataGrid.DataContext = listTreeNoText;

    }

------------------------------------
------------------------------------
I will be surprised if you read as far as this but if you have, thankyou.

As I said before, I know I am asking a lot, so an answer to either one of the above scenarios would be extremely well received. An answer to both would be outstanding.

Waiting in anticipation,
Pete.





0
Valentin.Stoychev
Telerik team
answered on 18 Aug 2008, 10:34 AM
Hi Pete,

All these are great scenarios and we will cover them in the Help topics. Give us some time and we will try to address them and prepare working examples.

Thanks!

Greetings,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meerkat
Top achievements
Rank 1
answered on 18 Aug 2008, 01:18 PM
Hello Valentin,

It was really good to hear that help is on its way.
In order to help with my project planning, would it be too much to ask if you are talking about days, weeks or months before I am likely to be able to use your RadTreeView component

Many thanks,
Pete.
0
Valentin.Stoychev
Telerik team
answered on 18 Aug 2008, 01:27 PM
Hi Pete,

The help will be ready till the end of this month. We will provide you with the examples in the next couple of days.


All the best,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meerkat
Top achievements
Rank 1
answered on 18 Aug 2008, 01:37 PM
Hello Valentin,
 
You cannot be fairer than that.
I will wait patiently.

Many many thanks.
 
Regards,
Pete.
0
Kiril Stanoev
Telerik team
answered on 27 Aug 2008, 02:14 PM
Hello Pete,

First I would like to apologize for the long delay, but the subject was way too interesting to leave it with an unclear explanation.

I have posted a blog that explains how to populate RadTreeView using a WebService and little bit of LINQ.
You can find the article here : Populating TreeView from WCF Service

In the blog post you will see how to transform flat data from a database into hierarchical one and bind that hierarchical data to RadTreeView.

If you have any additional questions or comments, do not hesitate to contact us.

Best wishes,
Kiril Stanoev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meerkat
Top achievements
Rank 1
answered on 28 Aug 2008, 09:11 AM

Hello Kiril,

Before I continue, I would like to thank you for at least making an effort to help. Apart from not mentioning the several 'usings' needed in the classes (very minor point) your example was extremely clear as far as it went. I am sure it will be very useful for one or two people but it only answered half my question.

Your example does not use an asymmetrical tree. I tried to explain what I mean by this in my earlier message dated 8/18/2008 5:09:28 AM. but it seems I may not have made it clear enough.

It would be great if all trees were like record and book collections, but many have varying branch levels.

I strongly suspect what I am trying to do is so painfully obvious to you, that you do not feel it worth mentioning. However, it is not obvious to me what changes are needed to make things work with asymmetrical trees.

If such trees are not possible using your control, I would be very grateful if someone could tell me. I am sure this is not the case however, and I am looking forward to hearing from you again.

Very best wishes,

Pete.

0
Accepted
Kiril Stanoev
Telerik team
answered on 29 Aug 2008, 08:45 AM
Hi Pete,

I would recommend you take a closer look at the "Template Selector Example" of the TreeView.
http://demos.telerik.com/silverlight/#Examples/TreeView/TemplateSelector

Also you can find information on "Data Templating" in MSDN and more specifically on how to style an ItemsControl here.

Let us know, as soon as possible, whether this solves the issue.

Greetings,
Kiril Stanoev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meerkat
Top achievements
Rank 1
answered on 29 Aug 2008, 10:50 AM
Hello Kiril,
Thankyou for your reply.
The fact that you directed me to the "Template Selector Example" suggests that I did not explain my problem very well. As I said before, the solution was probably so painfully obvious to you that you probably could not believe anyone could be so stupid that they could not see it.
I thought the template would only work with the fixed format shown in your example- i.e every Actor HAD to have one Name, one Position, and one Speciality. The examples I gave earlier where not like that at all.

I cannot apologise enough for being unable to work out how to make your example more realistic, and for wasting your time. I would also like to thank you once again for your patience with such a slow witted customer.
All works fine, now that I finally understand how things work (the Help files supplied with your latest Beta helped a great deal).

Many many thanks,
Pete.
0
Amruta
Top achievements
Rank 1
answered on 06 Jan 2010, 01:27 PM
Hello Kiril,

I was trying to access the link "Populating TreeView from WCF service" but i was not able to get the page. It shows me 404 error.

I want to build a silverlight application which uses a rad treeview.
I have a search button which will call a web service. A web service will take a "keyword" parameter and will search database. It will run some query and will return the result. I want to bind this result to a rad tree view.
As per my knowledge , a treeview can have 3 types of binding sources - Object , XML and WCF services.

I am searching huge amount of data using the web service and it returns large amount of records which i want to show as seperate nodes of a tree view. These records will act as a sub node in the tree view.

Do i need to use XML to bind the data to the tree view? If yes , how can i convert the linear data into XML file?
Can i directly bind the data to treeview by using any other approach? if yes , please suggest the best approach (XML or direct data binding ) to work with the large amount of data.


any help would be appreciated.

Thanks
Amruta.
0
Valentin.Stoychev
Telerik team
answered on 07 Jan 2010, 06:52 AM
Hi Amruta,

please check this help article. Let us know if manage to sole your problem, or otherwise how the article can be improved:
http://www.telerik.com/help/silverlight/radtreeview-populating-with-data-databinding-to-wcf-service.html

Best wishes,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amruta
Top achievements
Rank 1
answered on 15 Jan 2010, 06:27 PM

Hi Valentin,

Thank you for the link. Will check if it helps me to solve my problem.

I have another queries.

1.  can i use a simple sql query with ado.net instead of LINQ to retrieve data from database using web service , return the data and bind the data to the treeview? I think silverlight uses LINQ.
2. I have some static nodes in the treeview (E.G. I can have a treeview having 4 nodes "East" , "West" , "South" , "North") and i want to fetch the data using web service and create child nodes (like creating dynamic child nodes for "East" by fetching the list of customers living in east zone. The 4 nodes are always there , i just want to populate the child nodes for each. If there are no customers living in "North" zone , i still want to show the "North" Node and there will be no child nodes for it.  ).
3. If i want to fetch data from multiple tables and return the result in a list , how can we achieve that? (using web service)

I would really appreciate if you try to answer these questions. Its really urgent.

Thanks

 

0
Tihomir Petkov
Telerik team
answered on 18 Jan 2010, 01:37 PM
Hello Amruta,

1. You are in no way obliged to use LINQ. Here is a link to a tutorial explaining the generic usage of Silverlight with web services:
http://silverlight.net/learn/quickstarts/webservices/
2. There should be no problem with that scenario. Simply get the needed data when the LoadOnDemand event is fired by an item. You can refer to the help article regarding the load on demand functionality:
http://www.telerik.com/help/silverlight/radtreeview-features-load-on-demand.html
3. Yes, this is possible and there should not be any problems. How you merge the data from the different tables depends entirely on your needs (inner join, etc). For more details please search online for sql and web services tutorials - the logic in your service and its implementation is independent from the usage of the RadTreeView control.

Regards,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Charles Chukwu
Top achievements
Rank 1
answered on 24 Feb 2010, 11:19 AM
Hi,

I saw this thread and it got me really interested to know that the nodes in a templated node TreeView can be loaded with Xml. Let me say Valentin and the others did a great job back there. However, i have a quite different scenario.
My application loads from an isolated file storage file (a notepad, *.txt) and sets their header property before it adds the Tree nodes dynamically during runtime.
This part works fine. Now the problem is that i want images to be displayed in the nodes at the same time the headers are being  set. But its not working.

I set the ImageBaseDir of the TreeView in the xaml to the Images folder i.e. "\AppName\Images\". Then for each node i set the DefaultImageSrc property to the Header + ".png" or ".jpg" depending on the file involved. Now I thought it was because i was doing it in the code behind but i tried it statically as in setting it in the xaml but it still didn't work. Please is there anything i'm leaving out. Kindly let me know. Thank you.

Charles.
0
Valentin.Stoychev
Telerik team
answered on 24 Feb 2010, 11:42 AM
Hello Charles Chukwu,

We are not aware of such a problem. Can you open a support ticket and send us the project so we can debug it localy.

Thank you in advance for your cooperation.

Best wishes,
Valentin.Stoychev
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
Rodri
Top achievements
Rank 1
answered on 29 Jun 2010, 01:13 PM
hello friend, im new on silverligth... and i need some welp please,

Have you already managed to solve the problem with the interaction between SQL and treeview? you have some example that I can send me?

greetings and thanks Rodrigo Aires

0
Kiril Stanoev
Telerik team
answered on 01 Jul 2010, 03:03 PM
Hello Rodri,

There have been numerous improvements in RadTreeView over the time. Currently we are not aware of a problem between SQL, WCF and RadTreeView. Could you please open a support ticket explaining in bit more details the error you receive. It would be great if you can attach a sample project reproducing the issue. This way we will be better able to assist you.

On a side note, I'd like to inform you that we've just released an online tool that allows you to reduce the size of your Silverilght applications. For more information, please visit http://blogs.telerik.com/blogs/posts/10-06-10/telerik_assembly_minifier.aspx

Best wishes,
Kiril Stanoev
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
Mart-Mari
Top achievements
Rank 2
answered on 12 Oct 2010, 10:11 AM
Hallo,

I am very new to Silverlight and WCF so this may be very a stupid question. I apologize beforehand if it is.

I've read through the "Binding to WCF Service" atricle, and implemented almost all of it, but I am not 100% successful at it. When I declare my datasource static resource in the xaml, I get the dreaded wriggle blue error line under it saying that "Cannot create an instance off '<My Datasource name>'". This error disappears when I remove all reference to the  service client and data contracts from my datasource class. What I'd like to try do is set my DataContext from outside the xaml. In other words where you have a static resource:

<example:NorthwindDataSource x:Key="DataSource"/>

I'd like to leave this out and get my datasource from elsewhere in my application. How would the tree declaration's ItemSource then look? In the article it looks like this:

<telerikNavigation:RadTreeView x:Name="radTreeView" Margin="8"
   
IsLoadOnDemandEnabled="True" IsExpandOnSingleClickEnabled="True"
   
LoadOnDemand="radTreeView_LoadOnDemand"
   
ItemTemplate="{StaticResource CategoryTemplate}"
   
ItemsSource="{Binding Source={StaticResource DataSource}, Path=Categories}"/>

Kind regards,

Mart-Mari
0
Alex Fidanov
Telerik team
answered on 14 Oct 2010, 12:04 PM
Hello Mart-Mari,

What you could do is not specify the ItemsSource binding of the RadTreeView with a StaticResouce markup extension. You can just bind it like so ItemsSource="{Binding }". This binding expression will automatically bind to any data context set in the ancestor chain of elements of the RadTreeView. Then, you can set the DataContext of the RadTreeView or any of its ancestor elements to the data source returned from the Web Service in procedural code. The binding will automatically pick up the propertu value changing and will set the ItemsSource accordingly.

Best wishes,
Alex Fidanov
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
Meerkat
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Meerkat
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Amruta
Top achievements
Rank 1
Tihomir Petkov
Telerik team
Charles Chukwu
Top achievements
Rank 1
Rodri
Top achievements
Rank 1
Mart-Mari
Top achievements
Rank 2
Alex Fidanov
Telerik team
Share this question
or