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

Getting CheckedItems without opening all the nodes

3 Answers 47 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 09 Sep 2010, 10:47 AM
Hello,
I've got a 5 level nested treeview,  the last level got the ID i need to process...
When the treeview loads (it has a lot of items, almost 15.000) it's collapsed and the user can choose to drilldown or to check the root level and generate a report clicking on a button....

The problem is I won't get the CheckedItems of the leaf till I open the previous 4 level.... its' not good since I can't ask the user to opeen each n-tier level and neither I can start it expanded... I've tried setting IsVirtualized = false but got no luck

Thanks

Paolo

3 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 14 Sep 2010, 03:36 PM
Hello Paolo,

The problem with such scenarios is that due to the large number of items, their containers (RadTreeViewItem) will not be created. That is why the check logic has to be implemented within the ViewModel itself i.e. the ViewModel has to keep a collection of all the checked items. I've prepared a sample project that demonstrates one possible workaround to this scenario.
In it, my ViewModel has 2 properties - CheckedItems (a collection that contains all the checked items) and DataItems (a collection with all the items). The CheckedItems and DataItems collections are of type ObservableCollection<DataItem>. DataItem is a hierarchical object - it has 4 properties - Name, ViewModel, CheckState and Children.
Name is just a string representation for the item. Children is a collection of type ObservableCollection<DataItem> and contains all the sub-items.
CheckState is a property of DataItem that is bound to the CheckState of RadTreeViewItem via ContainerBindings. When CheckState in DataItem is set, I use the ViewModel property to add/remove the current DataItem from the CheckedItems collection of the ViewModel:

public ToggleState CheckState
{
    get
    {
        return this.checkState;
    }
    set
    {
        if (this.checkState != value)
        {
            this.checkState = value;
 
            // Raise property changed
            this.OnPropertyChanged("CheckState");
 
            // If the DataItem is checked
            //  1. add it to the CheckedItems collection
            //  2. check all its sub-items
            if (this.checkState == ToggleState.On)
            {
                this.ViewModel.CheckedItems.Add(this);
 
                foreach (var item in this.Children)
                {
                    item.CheckState = ToggleState.On;
                }
            }
 
            // If the DataItem is unchecked
            //  1. remove it from the CheckedItems collection
            //  2. uncheck all its sub-items
            if (this.checkState == ToggleState.Off)
            {
                this.ViewModel.CheckedItems.Remove(this);
 
                foreach (var item in this.Children)
                {
                    item.CheckState = ToggleState.Off;
                }
            }
        }
    }
}

Basically, the rule of thumb in such, scenarios where the hierarchy is deep, is to maintain the checked items in the ViewModel and not rely on the containers (RadTreeViewItems) since they might not be created. Imagine all the containers were created for your particular scenario - 15.000 items. It would be a performance hell IMHO.

Let me know if you have additional questions or comments regarding this scenario.

Kind regards,
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
Michele
Top achievements
Rank 2
answered on 14 Sep 2010, 03:49 PM
Hello Kiril,
do you think I can implement this in thew WebServer then pass it to SL or have I to create this object when the call for getting the data has been done?
Thanks
Paolo
0
Kiril Stanoev
Telerik team
answered on 16 Sep 2010, 02:50 PM
Hello Paolo,

After you receive the data from the web server, you have to create the objects(ViewModel) on the Silverlight client. More on WCF Ria services you can find here.

All the best,
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
Tags
TreeView
Asked by
Michele
Top achievements
Rank 2
Answers by
Kiril Stanoev
Telerik team
Michele
Top achievements
Rank 2
Share this question
or