I am using a TreeView with databinding and using virtualization (property isvirtualizing set to true). When I check or uncheck all, the treeview just update the current displayed items. Is there some way to check all items using virtualization?
best regards,
Gonçalo
20 Answers, 1 is accepted
I am not sure how you implement the "check/uncheck all" functionality, but you should keep in mind that when the RadTreeView is virtualized, it creates containers only for those RadTreeViewItems that are insiede the viewport. Therefore, if you set the IsChecked property of the RadTreeViewItem then the operation will only work on the currently displayed items.
However, if the RadTreeView is databound, you can use ContainerBindings to bind the CheckState property of each RadTreeViewItem to an appropriate business property (read more).
I hope this information helps. Please let us know if we can further assist you.
Kind regards,
Tina Stancheva
the Telerik team
Regards,
Gonçalo
The TriState feature of the RadTreeView is exposed to allow such scenarios. However, it only affects the created RadTreeViewItem containers. Therefore, in cases when the RadTreeView is virtualized, this feature won't work.
Since the virtualization of the RadTreeView means that containers are created only for the RadTreeViewItems inside the viewport, it is best to implement the check/uncheck logic in the view model. For example, you can make sure that every time when a new value is set to a IsChecked business property, the change will affect all children as well.
I prepared a sample project illustrating this approach. Give it a try and let me know if it works for you or if you need more info.
Greetings,
Tina Stancheva
the Telerik team
Now if I chekck the parent node it will check the childs. (Its Working)
But now I think I may have another problem. The RadTreeView CheckedItems property does not have all the items selected.
I have to the same process to get all the items?
Kind regards,
Gonçalo
I am not if I understand your issue correctly. In the sample project I sent the CheckedItems collection is populated as expected. I modified the project slightly to illustrate that. Can you have a look at it and let me know if it works for you.
Best wishes,
Tina Stancheva
the Telerik team
The problem is in the second layer. If we have another layer: 0.1.2 it dont appear in the Checked items list.
I send you the exampled with the problem.
http://www.megaupload.com/?d=P86YWWVV
Kind regards,
Gonçalo
This is an expected behavior since the RadTreeView is virtualized and therefore only the visible items' containers are initialized and those are the only items that the RadTreeView is aware of. Therefore the RadTreeView and the RadTreeView.CheckedItems collection isn't aware of any deeper-level checked items.
However, in the case when the RadTreeView TriStateMode feature is implemented, the RadTreeView evaluates the checked item's immediate children in order to determine the item's proper state. Therefore in the sample project the CheckedItems collection contains only the checked item and its immediate checked children.
So, indeed, you will need to implement your own logic to keep the checked items in a custom collection.
Also, I noticed a small issue in my code sample. In the DataItem class implementation I set the child.isChecked private property by mistake. The code should be:
public
bool
IsChecked
{
get
{
return
this
.isChecked;
}
set
{
if
(
this
.isChecked != value)
{
if
(
this
.Children.Count != 0)
{
foreach
(DataItem child
in
this
.Children)
{
child.IsChecked = value;
}
}
this
.isChecked = value;
OnPropertyChanged(
"IsChecked"
);
}
}
}
I also modified the sample project to illustrate a possible approach towards keeping all checked items in a custom collection. Please give it a try and let me know if it works for you.
On a side note, I just wanted to ask you to keep in mind that the Virtualization of the TreeView is implemented in order to optimize the Tree's performance when thousands of items have to be displayed. Therefore, if your TreeView is not designed to display a big amount of items, it is better not to virtualize it. I am mentioning that since your scenario requires you to work with the entire collection of items, rather than just with the visible once and since this is against the Virtualization logic, you will have to implement most of your custom logic in the ViewModels.
I hope the info helps. Please let me know if I can further assist you.
Sincerely yours,
Tina Stancheva
the Telerik team
<
telerik:RadTreeView MinHeight="100" ItemTemplate="{StaticResource Level1Template}" ItemsSource="{Binding Path=Activities}" IsVirtualizing="False" ItemsOptionListType="CheckList" IsOptionElementsEnabled="True" IsTriStateMode="True" Style="{StaticResource RadTreeViewStyle}">
And if I have a collapsed treeview, check a checkbox on the root, then expand the treeview I do not have the children checkboxes checked. See attached image.
Looking into your xaml I think that it should be working. :s
I'm not an expert, but I will suggest you to try comment the Style={StatickResource}. Maybe is your style. I dont know.
Just trying to help you. :)
Best regards,
Gonçalo
Try that too.
BTW: I'm using the Q1 2011 release.
@Scott
Could you please examine my test project and let me know f I have missed something? Thank you for your cooperation.
Regards,
Petar Mladenov
the Telerik team
Hi Petar,
Yes there was a problem with you example. If you add a ContainerBindingCollection to your HierarchicalDataTemplate it will show the problem. I cannot attach a zip file so I opened a support ticket.
This is what I have in the XAML from your example that displayes the problem:
<
telerik:ContainerBindingCollection
x:Key
=
"BindingsCollection"
>
<
telerik:ContainerBinding
PropertyName
=
"CheckState"
Binding
=
"{Binding Path=Checked, Mode=TwoWay}"
/>
</
telerik:ContainerBindingCollection
>
<
telerik:HierarchicalDataTemplate
x:Key
=
"Activity_Level3Template"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource BindingsCollection}"
>
<
TextBlock
Foreground
=
"DarkBlue"
Text
=
"{Binding Path=Name}"
/>
</
telerik:HierarchicalDataTemplate
>
<
telerik:HierarchicalDataTemplate
x:Key
=
"Activity_Level2Template"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource BindingsCollection}"
ItemTemplate
=
"{StaticResource Activity_Level3Template}"
ItemsSource
=
"{Binding Path=Children}"
>
<
TextBlock
Foreground
=
"DarkGreen"
Text
=
"{Binding Path=Name}"
/>
</
telerik:HierarchicalDataTemplate
>
<
telerik:HierarchicalDataTemplate
x:Key
=
"Activity_Level1Template"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource BindingsCollection}"
ItemTemplate
=
"{StaticResource Activity_Level2Template}"
ItemsSource
=
"{Binding Path=Children}"
>
<
TextBlock
Foreground
=
"DarkRed"
Text
=
"{Binding Path=Name}"
/>
</
telerik:HierarchicalDataTemplate
>
</
Grid.Resources
>
<
telerik:RadTreeView
MinHeight
=
"100"
IsVirtualizing
=
"False"
ItemsOptionListType
=
"CheckList"
IsOptionElementsEnabled
=
"True"
IsTriStateMode
=
"True"
ItemTemplate
=
"{StaticResource Activity_Level1Template}"
ItemsSource
=
"{Binding Path=TreeItems}"
/>
Please take a look at this updated version of Peter's sample and let me know whether it works according to your specifications.
Regards,
Kiril Stanoev
the Telerik team
Please look at the attached image from your example.
1) Parent2 is unchecked but all the children are in an intermediate state (invalid state)
2) Parent3 is checked but all the children are in an intermediate state (invalid state)
3) Parent4 is in an intermediate state and so are all the children (invalid state)
4) Play with checking and unchecking the boxes and you will notice that is doesn't behave quite right
Please first accept our apologies for not being clear in our previous posts.
Actually we are aware of this issue and we have logged it in our PITS. The real problem is that currently when using the TriState mode of the RadTreeView and ContainerBindings, the bindings are with higher priority. So currently, when using container bindings, you will have to take care of the implementation of tristate logic on your own. We will implement this to be realized out of the box but we cannot provide an estimated time for this issue. You can now vote for it and this way increase its priority. Thank you for your cooperation.
All the best,
Petar Mladenov
the Telerik team
This seems like a very fundamental feature of the TreeView which is not working correctly.
Thanks for any consideration.
We will work on RadTreeView`s issues after the official Q2 2011 release scheduled for the middle of July.
Please accept our apologies for any inconvenience caused.
Kind regards,
Petar Mladenov
the Telerik team
Unfortunately, we cannot provide an estimated time frame when this will be resolved. As a workaround we highly suggest you to implement the TriState logic in your ViewModels on your own. As for the CheckState setting before the items is generated, we cannot determine this as a bug because this is expected by design. We described this behaviour in this forum thread.
Please let us know if you have further questions.
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>