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

TreeView Asynchronous Data, LoadOnDemand, and Data Binding

3 Answers 212 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 27 Jan 2011, 04:57 PM
I'm trying to understand how to use your Load On Demand funtionality, and data binding while retrieving data Asynchronous from a server.

I have found examples that show how to "load on demand" and "data bind" to observable collections but the examples get data syncronously. Those examples have the benifit of always generating the data directly in the "LoadOnDemand" event and/or having ALL the data loaded at the beginning of the tree load process then used in the event. When I say the examples are syncronous here, I mean that the data is alway exists before the "LoadOnDemand" event is finished.

I'm not sure what to do when the data will not exist at the time of the "LoadOnDemand" event and won't exist for some time after. I'm thinking that event will finish and some additional steps will need to take place to get the treeviewitem populated and expanded once that data is returned Asynchronous from the server.

We use the MVVM and MVC in our architecture. In my thoughts, I can see it working something like this but not sure how to put it together with your control and it's events. It almost seems like I need to manipulated events somehow or need a better understanding.

Let's say the treeview is bound to an observable collection;

 

  1. Data is loaded into the silverlight tree view root upon loading the component. (which would happen asynchronously).
  2. At this point let's say that their are 5 "root" nodes in the tree.
  3. At this point the observable collection contains only "root" nodes. No data has been queried for any children.
  4. None of the "root" children are expanded at this point and there is no child data yet loaded into the observable collection. The user clicks a "root" node and wants to expand it to show the "children".
  5. We will need to request the data from the web server.............
  6. The “LoadOnDemand” event is trigged (per you examples).
  7. This is where I'm not sure what to do based on the existing examples..........
  8. Upon, the “LoadOnDemand” event triggering, we would call our ViewModel and tell it to request data from the Model. (Through mechanism that don't pertain here, the server side code will query a database and send back data. At a later point, the Model will eventually send the data back to the ViewModel. )
  9. At this point the “LoadOnDemand” event won’t have new "child" data from the server because it’s coming asynchronously at a later point.
  10. Which means the “LoadOnDemand” event will exit without having the "child" data.
  11. At some point the data will be returned from the server and placed somewhere. Proably in the observable collection which needs to update the tree view "root" with it's children, render those children and expand the parent correctly.
  12. This is what I'm not undestanding how does #11 get tied all together to make it work happily.

 

Can you provide a sample solution? A solution that doesn't have the data at the time the "LoadOnDemand" event is triggered and finished? Then sometime after that the data exists and the root gets populated, expanded, and all the children show? Our tree will have many levels but a basic example will help me understand what to do.

How does the Asynchronous data get loaded into the correct tree view "root" with it's children, render those children and expand the parent correctly.

 

An example of this would help me out tremendously. Are their any examples of doing this asynchronously?



3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 28 Jan 2011, 04:56 PM
Hi John,

Could you please examine the attached project which could be a good starting point. It shows how to bind a TreeView to a DataBase using Wcf Ria Services and LoadOnDemand. It uses the Northwind Database you can download from here. If you have any questions on this - do not hesitate to ask.

Regards,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
John
Top achievements
Rank 1
answered on 28 Jan 2011, 08:31 PM

I downloaded the NorthWinds db and installed it into SQL Server 2005. I can see the db and tables when I open SQL Server Management window. I can compile the source you zipped.

I get the following error when I run the application. I see that it's trying to use my windows authentication. Is their a setting inside the application that I need to change? What database permissions do I need to set-up to get this to run?

{System.ServiceModel.DomainServices.Client.DomainOperationException: Load operation failed for query 'GetCategories'. The underlying provider failed on Open. Inner exception message: Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'APX\john'.
   at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
   at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
   at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
   at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )}
0
Albert
Top achievements
Rank 1
answered on 29 Jan 2011, 02:56 PM
Hi John,

You have to adjust the web.config file:
 <add name="NorthwindEntities" connectionString="metadata=res://*/ModelNorthwind.csdl|res://*/ModelNorthwind.ssdl|res://*/ModelNorthwind.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=YOURSERVERNAME;Initial Catalog=Northwind;Persist Security Info=True;User ID=SQLUSERNAME;Password=SQLPASSWORD;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

Off cource you can also use windows authentication for the connection with your database.

Best wishes,
Albert
Tags
TreeView
Asked by
John
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
John
Top achievements
Rank 1
Albert
Top achievements
Rank 1
Share this question
or