How to change forecolor of specific node text in NodeFormatting

7 posts, 1 answers
  1. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 30 May 2011 Link to this post

    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
  2. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 31 May 2011 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Svett
    Admin
    Svett avatar
    728 posts

    Posted 03 Jun 2011 Link to this post

    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.
  5. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 03 Jun 2011 Link to this post

    " 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
  6. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 08 Jun 2011 Link to this post

    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.
  7. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 08 Jun 2011 Link to this post

    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
  8. Svett
    Admin
    Svett avatar
    728 posts

    Posted 13 Jun 2011 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready