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

How to change forecolor of specific node text in NodeFormatting

6 Answers 261 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
SUNIL
Top achievements
Rank 2
Iron
SUNIL asked on 31 May 2011, 02:27 AM
I used the following code without success. The forecolor is supposed to change to red but it doesn't. How would I make the forecolor change to red in code below. I am using latest version of controls.
Thanks
Sunil

If e.Node.Text = GroupNameRadTextBox.Text.Trim() Then
            e.NodeElement.BackColor = Color.LightYellow
            e.NodeElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
            e.NodeElement.ForeColor = Color.Red
            e.NodeElement.DrawFill = True
        Else
            e.NodeElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.NodeElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.NodeElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.NodeElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local)
        End If

6 Answers, 1 is accepted

Sort by
0
SUNIL
Top achievements
Rank 2
Iron
answered on 31 May 2011, 10:48 PM
I found the answer, though it doesn't sound intuitive. To change forecolor in NodeFormatti9ng event, simply change e.Node.ForeColor, and not  e.NodeElement.ForeColor. Why is it like this, is beyond  me? I would have expected e.NodeElement.Forecolor to work.
0
Svett
Telerik team
answered on 03 Jun 2011, 08:21 AM
Hello Sunil,

I am glad to hear that you have addressed the issue on your own. You can use the ForeColor property of the logical RadTreeNode instance. Even more, you can use it outside the NodeFormatting event. If you are setting the ForeColor property of the visual TreeNodeElement instance, you should do it only in the NodeFormatting event.

Regards,
Svett
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
SUNIL
Top achievements
Rank 2
Iron
answered on 03 Jun 2011, 02:22 PM
" If you are setting the ForeColor property of the visual TreeNodeElement instance, you should do it only in the NodeFormatting event."
It doesn't work in NodeFormatting event
when I set forecolor of TreeNodeElement. This seems to be an issue.  That was what I tried before posting a message here.
Thanks
Sunil
0
Accepted
Svett
Telerik team
answered on 08 Jun 2011, 04:16 PM
Hello Sunil,

I did not notice the mode you are using the RadTreeView in. If you are using it in full row select mode, then you should set the properties of TreeNodeElement. When you are not using full row select mode, you should use the TreeNodeContentElement by accessing the ContentElement property of the node visual element:

void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
    e.NodeElement.ContentElement.BackColor = Color.Red;
}

 

Greetings,
Svett
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
SUNIL
Top achievements
Rank 2
Iron
answered on 08 Jun 2011, 04:44 PM
That's a very complex way of doing things.
I mean I need to know rocket science to do that. How would a developer ever think of using ContentElement?
NodeElement is quite an intuitive way of changing appearance, but  for some reason, Telerik adds 'unnecessary' complexity with each new version.
I do not like the model you have described. I have to wait for a day or 7 days to know that some mysterious object called  ContentElement needs to be used to change appearance of a tree node. Not at all productive from a developers point of view, in my opinion.

Thanks
Sunil
0
Svett
Telerik team
answered on 13 Jun 2011, 04:41 PM
Hi Sunil,

Thank you for your feedback regarding usability of our framework.

When we plan and develop a feature or a whole control we take into consideration several key points such as performance, the features that our customers demand and of course ease of use. We are trying to cover the features that a control offers with flexible and powerful API, balancing between user-friendly API and performance. Still, there are situations where we can't satisfy both and therefore the API of RadTreeView is as it is. This allows RadTreeView to offer the features that you, our customers have requested, without affecting the performance.

I hope that this clarifies the case. If you have additional questions, feel free to write back.

Best wishes,
Svett
the Telerik team

Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
Treeview
Asked by
SUNIL
Top achievements
Rank 2
Iron
Answers by
SUNIL
Top achievements
Rank 2
Iron
Svett
Telerik team
Share this question
or