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

RADTreeView usin "QueryableDomainServiceCollectionView "

10 Answers 140 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ben Hayat
Top achievements
Rank 2
Ben Hayat asked on 12 Feb 2011, 08:52 AM
Hi;

It would be very helpful to have a sample part of your DEMO, showing RADTreeview working with WCF RIA Services using the new collection (QueryableDomainServiceCollectionView ) from RADDataSource for RIA Services.

Thanks!
..Ben

10 Answers, 1 is accepted

Sort by
0
MikeWiese
Top achievements
Rank 1
answered on 14 Feb 2011, 03:10 PM

Hi Ben, I feel your pain. I tried binding my RadTreeListView directly to a QueryableDomainServiceCollectionView exposed by my view model but I had quite a bit of trouble with this because the EntityQuery I use returns all of my objects, not just the top-level one. So I saw all of my entities displayed at the top level, not just my root node.

My entities (and yours too, I suppose) have parent-child relationships by virtue of a self-referencing parentId which is defined at the database level, detected by the Entity Framework and honoured by the RadDomainDataSource. It seemed potentially elegant to make use of those relationships, but I couldn't find any properties or events of the QueryableDomainServiceCollectionView that would help me to restrict the top-level objects to just those where the parent object is null.

I got something working in the end - it doesn't feel particularly neat, but the following may work for you, too:

I hooked the LoadedData event of my QDSCV, and in there I iterated through all of the Entities returned. If I found one with no Parent, I stored it in an ObservableCollection created just to hold references to the top-level Entities...

// internal collection of top-level plant elements
private ObservableCollection<PlantElement> topLevelElementCollection = new ObservableCollection<PlantElement>();

// The QDSCV that we're all trying to use to drive hierarchical controls
private QueryableDomainServiceCollectionView<PlantElement> view;

// View Model constructor, somewhat edited for clarity (I hope)
public MyViewModel()
{
    MyDomainContext context = new MyDomainContext();
    EntityQuery<PlantElement> query = context.GetPlantElementsQuery();
    this.view = new QueryableDomainServiceCollectionView<PlantElement>(context, query);
    this.view.LoadedData += this.View_LoadedData;
    this.view.Load();
}

// Method called when my query returns, with no error handling or other nice stuff
private void View_LoadedData(object sender, Telerik.Windows.Controls.DomainServices.LoadedDataEventArgs e)
{
    // Of all the entities we got back, the root node is the one with no parent.
    foreach (var entity in e.Entities)
    {
        PlantElement plantElement = entity as PlantElement;
        if (plantElement != null)
        {
            // N.B. I did edit some relationship properties in my EF model to give me nice property names like
            // 'ParentElement' and ChildPlantElementCollection - the autogenerated names were not helpful at all.
            if (plantElement.ParentElement == null)
            {
                // we found a top-level element - remember it for later
                this.topLevelElementCollection.Add(plantElement);
            }
        }
    }
}

I then exposed the top-level entities through a view model property:

public ObservableCollection<PlantElement> TopLevelPlantElementCollection
{
    get
    {
        return this.topLevelElementCollection;
    }
    set
    {
        this.topLevelElementCollection = value;
        OnPropertyChanged("TopLevelPlantElementCollection");
    }
}

This is the property my RadTreeListView bound to. I didn't bind to the QDSCV like all the Telerik examples:

<telerik:RadTreeListView x:Name="radTreeListView" 
                     ItemsSource="{Binding TopLevelPlantElementCollection}">

    <telerik:RadTreeListView.ChildTableDefinitions>
        <telerik:TreeListViewTableDefinition ItemsSource="{Binding ChildPlantElementCollection}" />
    </telerik:RadTreeListView.ChildTableDefinitions>

</telerik:RadTreeListView>

It seems it was enough to bind to the ObservableCollection of top-level elements, then the RadTreeListView just followed the ChildPlantElementCollection property downwards from there.

Hope there's enough similarity with your case to be of some help.

0
Ben Hayat
Top achievements
Rank 2
answered on 14 Feb 2011, 04:06 PM
Mike, thanks a bunch;
Yes, the self referencing is the part that I'd like to see a solution from Telerik and rather than creating separate collection for the top level. In my case, similar to Desktop File Directory, where the user can create deeper folders, I need all to be in one collection and at the same (if possible) take advantage of LoadOnDemand feature. I'll look at the code in more detail later on.

Let's see what team has to say and offer with the new QDSCV.
Thank you again.
..Ben
0
Ben Hayat
Top achievements
Rank 2
answered on 14 Feb 2011, 11:55 PM
@Team:
I'd like to extend my request that any demo or docs provided for my request would also describe and highlight using QDSCV in relation to TreeView's ItemsControl and Containers.

TreeView seems to be very deep and I'm trying to minimize the learning curve while using it with RIA services and QDSCV.
Your help will be appreciated.

Thanks!
..Ben
0
Ben Hayat
Top achievements
Rank 2
answered on 16 Feb 2011, 03:42 PM
Any response from team to this post?
Thanks!
0
Alex Fidanov
Telerik team
answered on 17 Feb 2011, 04:21 PM
Hello Ben Hayat,

The QDSVC is just a collection it will work with RadTreeView. However, the collection is not hierarchical so you'll need to implement this with your custom logic. The closest example that we have for this you can find here: ttp://demos.telerik.com/silverlight/#DataVirtualization/VariousControls.

Please let us know if that is helpful to you.

All the best,
Alex Fidanov
the Telerik team
0
Ben Hayat
Top achievements
Rank 2
answered on 17 Feb 2011, 04:37 PM
Hi Alex;

Thanks for the link. I had not seen this demo before, since I was mainly looking at the TreeView section.
This demo raises another question regarding the difference between "Virtualization" and "LoadOnDemand" features for TreeView.

I'm trying to figure out what steps I need to follow in order to use TreeView successfully. There are too many things in TreeView and there is no guidance how these need to be coordinated. For Example, we have:
a) Hierarchical steps to implement
b) adding Self Referencing to it.
c) Building the proper hierarchical template.
d) Then addressing "LoadOnDemand"
e) Then Virtualization.
f) Then making sure the TreeView and Data provider stay in synch.
g) and other things.

I don't think the answer "The QDSVC is just a collection it will work with RadTreeView" gives a good explanation to above steps that are not clearly outlined in the docs. A complex control like TreeView needs some guidelines rather letting each person trying to figure out how the pieces need to be together. It just too much waste of time.

..Ben
0
Vlad
Telerik team
answered on 17 Feb 2011, 04:48 PM
Hello Ben,

 Generally QueryableDomainServiceCollectionView is not different compared to any other standard collection since this collection is not hierarchical - we do not have any hierarchical collection so far.

To achieve your goal you can create a model with nested QueryableDomainServiceCollectionView similar to the example with RadTreeView and VirtualQueryableCollectionView - you can check the code in ExamplesDataContext class. 

Kind regards,
Vlad
the Telerik team
0
Ben Hayat
Top achievements
Rank 2
answered on 17 Feb 2011, 05:02 PM
Hi Vlad;

Thanks for the pointer. I just opened the sample project to look at that class.

As I had asked Alex, how does Virtualization concept come into play with the LoadOnDemand feature and how should they both be coordinated?
I think not having clear picture of these all coming into one scene, make it harder to layout the path.
Thanks!
..Ben

p.s. If I'm doing a self referencing hierarchical treeview, do I still need to use Virtualization? The above mentioned sample seems to be dealing with multiple tables for hierarchial case. In my case, it's a single table using ID, ParentID for self referrencing to create Hierarchical.
0
Accepted
Kiril Stanoev
Telerik team
answered on 22 Feb 2011, 05:21 PM
Hi,

The Virtualization feature of RadTreeView controls how many RadTreeViewItems will be rendered on the screen. As any other virtualized control, RadTreeView will render only those RadTreeViewItems that are visible.

The LoadOnDemand feature allows you to assign ItemsSource to a RadTreeViewItem whenever you expand this RadTreeViewItem.

The best practice is to always turn on the Virtualization whenever your RadTreeView has a lot of items (no matter if you are using LoadOnDemand, binding RadTreeView to hierarchical data source or whatever).

All the best,
Kiril Stanoev
the Telerik team
0
Ben Hayat
Top achievements
Rank 2
answered on 22 Feb 2011, 05:27 PM
Excellent advice Kiro;

I hope the online docs gets more updated on the guidance and the "Why" part of things, to avoid confusion.
Thanks!
Tags
TreeView
Asked by
Ben Hayat
Top achievements
Rank 2
Answers by
MikeWiese
Top achievements
Rank 1
Ben Hayat
Top achievements
Rank 2
Alex Fidanov
Telerik team
Vlad
Telerik team
Kiril Stanoev
Telerik team
Share this question
or