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

Tracking source node on WCF call

1 Answer 68 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 28 Jan 2009, 02:41 AM
I'm sure I'm overlooking something simple, but here is the problem I face:

I have a LoadOnDemand TreeView that calls a WCF service to pull the data.  Originally, I stored a private RadTreeViewItem property in the calling control (currentItem), so when the WCF returned, I could add the children to currentItem node.

This method worked fine until we tested against a production data source, which could take approximately 5 seconds to return the requested data.  If the user selected a different node to expand during this time, my pointer reference would be messed up.  Effectively adding the nodes for Node A to Node B.

So now the question, what is the best practice to insure the WCF return is dealing with the original TreeViewItem?  I attempted to just send the RadTreeViewItem across as an object, but it will not serialized.

Another note:  My next thought was to send the FullPath of the node to WCF and return it with the results.  My question is, what if there are nodes with the same Header value.  Will they return the same path?

Any thoughts/suggestions would be greatly appreciated.

Thanks,
Tony

1 Answer, 1 is accepted

Sort by
0
hwsoderlund
Top achievements
Rank 1
answered on 29 Jan 2009, 12:54 PM
Do you have a unique identifier on the data objects that the treeview is bound against? If not, maybe you could create one. Then you could use that value to send to WCF and then back again, instead of sending the RadTreeViewItem or the full node path. By the way, you can use the auto-generated "userState" parameter to have something sent back and forth across the wire automatically, you don't have to code for it yourself. Of course that only applies if you use "Add service reference" to generate your proxy.

If you don't have a unique id I would suggest that you generate a GUID, slap that value in the Tag property of the RadTreeViewItem, send the same guid to wcf and then when you get it back in the userState parameter, just find the node and populate the children.

Yet another solution is to make your service call inline, like so (pseudo code):


//The clicked node 
RadTreeViewItem clickedNode = new RadTreeViewItem(); 
 
var MyClient = new ApplicationServices().GLSClient; 
MyClient.GetNodesCompleted += delegate(object sender, GetNodesCompletedEventArgs e) 
    //The same node will be available on callback 
    clickedNode.ItemsSource = e.Result; 
}; 
MyClient.GetNodesAsync(clickedNode.NodeID);

Tags
TreeView
Asked by
Tony
Top achievements
Rank 1
Answers by
hwsoderlund
Top achievements
Rank 1
Share this question
or