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

Change child node position

1 Answer 96 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Eduard
Top achievements
Rank 1
Eduard asked on 26 Sep 2014, 09:07 AM
Hello,

Is it possible to change all the child nodes position, to align with the root node. So all the nodes (root and child) will be aligned at the left. 
And one more question. Is it possible to change the color inside the checkbox or the radio button, and the text in black (in a treeview with checkboxes and radio buttons). 

Thank you in advance

Eduard

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Sep 2014, 01:31 PM
Hello Eduard,

Thank you for writing.

In order to achieve your goal it is suitable to use the NodeFormatting event. Thus, for all nodes from the child levels you can adjust the NodeElement.Margin property:
private void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
    if (e.Node.Level>=1)
    {
        e.NodeElement.Margin = new Padding(-20*e.Node.Level, 0, 0, 0);
    }
    else
    {
         e.NodeElement.Margin = new Padding( 0);
    }
}

As to the check mark, you can adjust its back color in the NodeFormatting event as well:
TreeNodeCheckBoxElement cb = e.NodeElement.ToggleElement as TreeNodeCheckBoxElement;
if (cb != null)
{
    cb.CheckMarkPrimitive.Fill.BackColor = Color.Yellow;
    cb.CheckMarkPrimitive.Fill.GradientStyle = GradientStyles.Solid;              
}

The node's text can be customized via the e.NodeElement.ContentElement.ForeColor property:
e.NodeElement.ContentElement.ForeColor = Color.Red;

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
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
Eduard
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or