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

Changing text color when a parent contains selected children

1 Answer 305 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Steve LaForge
Top achievements
Rank 1
Steve LaForge asked on 30 Jan 2009, 12:08 AM
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!
Steve

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 02 Feb 2009, 04:58 PM
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,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Steve LaForge
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or