Save checked item and change ItemSource

Posted by: darkthanhtam on 20 October 2020, 2:48 am EST

    • Post Options:
    • Link

    Posted 20 October 2020, 2:48 am EST

    Hi,

    I have tree view like this https://jsfiddle.net/LaAsCE/bo6knxym/

    I want when I change ItemSource then all item I was select at old ItemSource that saved and selected at new ItemSource.

    I tried use checkedItems to save at old ItemSource and set at new ItemSource but that didn’t work.

    Can you help?

    Regard~

  • Posted 21 October 2020, 9:57 am EST

    Hi darkthanhtam,

    We are sorry for the delayed response. Setting the checkedItems again will not work because the items in the checkedItems array need to have a reference in the itemsSource of the TreeView. When you reassign the itemsSource, the references of listItemSelected are broken. So, when you assign the checkedItems again, none of the items in this variable are bound to the treeview. That is why the items are not updated.

    To restore the checked states, you will need to recursively iterate over each item of the TreeView and check whether the current item is in the itemsSource and whether it needs to be checked and then update the checked state accordingly.

    Let us know if you face any issues while implementing this.

    Regards,

    Ashwin

  • Posted 21 October 2020, 11:35 pm EST

    Oh, I just thought that have a method support to do that faster. By the way, thanks for your response. I’ll do as your solution.

    Regards~

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels