preselect checkboxes

4 posts, 0 answers
  1. Sjors
    Sjors avatar
    9 posts
    Member since:
    May 2012

    Posted 09 May 2014 Link to this post

    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
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 09 May 2014 Link to this post

    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.
     
  3. DevCraft banner
  4. Sjors
    Sjors avatar
    9 posts
    Member since:
    May 2012

    Posted 23 May 2014 in reply to Pavel R. Pavlov Link to this post

    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)
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 26 May 2014 Link to this post

    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.
     
Back to Top