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

preselect checkboxes

3 Answers 87 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sjors
Top achievements
Rank 1
Sjors asked on 09 May 2014, 06:49 AM
I use the radtreeview with checkboxes and "tristate selection logic" 

After I have databound my radtreeview I want to check SOME of the checkboxes (to show the selection the user made previously)

I cannot seem to iterate through the tree-items properly to set the selection state.

The only option i have found so far is to not use the built-in-checkbox but bind to a custom one in my template (the mvvm example) but this means I have to implement the tristate logic myself. This on itself is not a very large problem but it seems unlikely to me that this would be necessary.

more info about the problem i'm having is on stack overflow here: http://stackoverflow.com/questions/23496122/preselect-checkboxes-in-radtreeview-silverlight

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 09 May 2014, 02:25 PM
Hello Sjors,

You are right that the tri-state logic of the RadTreeView control has limitations when it is used in MVVM scenario. We are aware of them but you need to have in mind that the built-in feature is designed to work with XAML defined control only. It does not support MVVM.

In order to achieve your requirement in MVVM scenario you can follow our Implement a Tri-State CheckBox logic using MVVM article. It demonstrates how you can control the state of the checkbox through your ViewModel.

Please give this approach a try and let me know if you need any further assistance.

Regards,
Pavel R. Pavlov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Sjors
Top achievements
Rank 1
answered on 23 May 2014, 12:28 PM
please note that my problem was not getting the checkbox control to work in tri-state-mode in the mvvm scenario

I was not using mvvm and I was trying to find a way to pre-check the checkboxes when the control loaded (show the user their previous selection)
The problem was that I did not seem to be able to force the tree to generate all the tree nodes so i could iterate through them and check the boxes. 

since i wasn't able to do that i "fixed" this by going to the mvvm scenario (with loss of tri state logic)
0
Pavel R. Pavlov
Telerik team
answered on 26 May 2014, 11:57 AM
Hello Sjors,

From your first post I concluded that you are using data-binding in your application. 

"After I have databound my radtreeview"

This is why in my previous reply I stated that the built-in tri-state checkbox logic is designed to be used in declaratively defined control, not in data-binding scenarios. This is why I suggested to follow the approach in the referenced article.
By following it, you will be able to bind the IsExpanded property of every RadTreeViewItem to property exposed by your view model. Furthermore, you will be able to control the 
IsChecked 
property of the custom CheckBox control in the template of the RadTreeViewItems. Once you have the references of the business items you will be able to save and load them as required. If your business object implements INotifyPropertyChanged interface the UI will be updated accordingly.

The most obvious reason behind not creating all UI elements whenever the RadTreeView control is loaded is the UI virtualization feature. If it is switched on the RadTreeView will create the items that can be fit in the current viewport of the control, only.

Regards,
Pavel R. Pavlov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
TreeView
Asked by
Sjors
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Sjors
Top achievements
Rank 1
Share this question
or