Changing text color when a parent contains selected children

2 posts, 0 answers
  1. Steve LaForge
    Steve LaForge avatar
    61 posts
    Member since:
    Feb 2005

    Posted 29 Jan 2009 Link to this post

    I have a two-level treeview with SingleExpandPath = true and CheckBoxes = true.  It is bound to a database.  I have used the scripts found on the Telerik site so that it will check all chidren when a parent is checked and unchecks a parent when any child is unchecked.

    When I load the treeview, I change the color of the parent if there are any child nodes checked.  This gives the user a quick visual that one or more of the child nodes for that particular parent are selected even if the parent is not.  My next step was to use the ClientNodeChecked event to walk through the checked nodes using treeview.get_checkedNodes and modifying the node.get_textElement().style.color for the parent or self.  My problem is when a node is unchecked.

    What I am looking for is 2-part:
    1.  A quick way to set any parents to a default color, then;
    2.  A quick way to set the color for all parents of a node

    I am trying to avoid trying to walk through every single node when a user checks / unchecks a box.  I'm hoping that there is an easy way - which I haven't found - to find out that a node has child nodes.

    Thanks in advance for your help!
  2. Yana
    Yana avatar
    4796 posts

    Posted 02 Feb 2009 Link to this post

    Hi Steve,

    You can set the default color of a node again like this:

    node.get_textElement().style.color = ""

    The only way to set color of all parent nodes is to walk through all of them:

    while(node != treeview)  
       node.get_textElement().style.color = "red";  
       node = node.get_parent();  

    Best wishes,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top