Change the treenode font size and color at runtime

6 posts, 0 answers
  1. Giri
    Giri avatar
    13 posts
    Member since:
    Oct 2008

    Posted 24 Nov 2008 Link to this post

    Hi,
                 In my project i am loading treeview with employee name's at the runtime.In default i am applying the skin "INOX" to the treeview.But  at the runtime  for the specific condition  i need to  change the particular  nodetext color to red and also the font size to be bold for that particular nodetext.
            How can i do this? I want to do this on server side ......

    help me immediately..............

    Regards,
    Giri..............
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2008 Link to this post

    Hello Giri,

    You can try setting the forecolor and font of the node as shown in the code snippet below:
    aspx:
    <telerik:RadTreeView ID="RadTreeView1" Skin="Inox" runat="server" OnNodeDataBound="RadTreeView1_NodeDataBound" OnPreRender="RadTreeView1_PreRender"
     <Nodes> 
       <telerik:RadTreeNode Text="Node1"
         <Nodes> 
           <telerik:RadTreeNode Text="SubNode11"></telerik:RadTreeNode> 
           <telerik:RadTreeNode Text="SubNode12"></telerik:RadTreeNode>   
           <telerik:RadTreeNode Text="SubNode13"></telerik:RadTreeNode>      
         </Nodes> 
       </telerik:RadTreeNode> 
       <telerik:RadTreeNode Text="Node2"
         <Nodes> 
           <telerik:RadTreeNode Text="SubNode21"></telerik:RadTreeNode> 
           <telerik:RadTreeNode Text="SubNode22"></telerik:RadTreeNode> 
           <telerik:RadTreeNode Text="SubNode23"></telerik:RadTreeNode> 
         </Nodes> 
       </telerik:RadTreeNode> 
     </Nodes> 
    </telerik:RadTreeView> 

    cs:
     protected void RadTreeView1_PreRender(object sender, EventArgs e) 
        { 
            foreach (RadTreeNode node in RadTreeView1.Nodes) 
            { 
                if (node.Text == "Node1") 
                { 
                    node.ForeColor = System.Drawing.Color.Red; 
                    node.Font.Bold = true
                }            
            }         
        } 

    Thanks
    Princy.
  3. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 01 Apr 2009 Link to this post

    I've also tried to do this, but I get an error saying that node.Font.Bold and node.Font.Italic is readonly?

    I've also tried the following:

    Font

     

    myfont = new Font(node.Font, FontStyle.Italic);

     

    node.Font = myfont;

    Then I get an exception saying that node.Font = null

    What am I missing?


    Regards, Jill-Connie Lorentsen

  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 01 Apr 2009 Link to this post

    Hello Jill-Connie Lorentsen,

    Here is the code I used which worked just fine:

    <telerik:RadTreeView ID="RadTreeView1" runat="server" Skin="Vista"
        <Nodes> 
            <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1"
                <Nodes> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2"
                    </telerik:RadTreeNode> 
                </Nodes> 
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" Text="Root RadTreeNode2"
                <Nodes> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2"
                    </telerik:RadTreeNode> 
                </Nodes> 
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" Text="Root RadTreeNode3"
                <Nodes> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                    </telerik:RadTreeNode> 
                </Nodes> 
            </telerik:RadTreeNode> 
        </Nodes> 
    </telerik:RadTreeView> 


    protected void Page_Load(object sender, EventArgs e) 
        foreach (RadTreeNode node in RadTreeView1.Nodes) 
        { 
            node.Font.Bold = true
            node.Font.Italic = true
        } 

    This made the text of all my root nodes to be Bold and Italic.

    What is different in your case?

    Sincerely yours,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 02 Apr 2009 Link to this post

    Nothing is different, - and I still get the message that the property is invalid.

    I've worked around the problem, and I now use the font of the tree view as a starting point, and it works fine.

     

     

    Font myfont = new Font(radTreeView.Font, FontStyle.Italic);

     

    node.Font = myfont;

  6. Trevor
    Trevor avatar
    13 posts
    Member since:
    Mar 2009

    Posted 14 May 2009 Link to this post

    Can I set the font size color and more importantly Bold when using an xml file.
    I am able to set the following:

    Text

    ImageUrl

    Expanded
    NavigateUrl
    But I am unable to set the font.

    ie.

     

     

     

    <Contracts Text="Contract #102" ImageUrl="~/TreeView/drafts.gif" Expanded="True"/ NavigateUrl="home.aspx"/>

     

     

     

     

    <Contracts Text="Contract #103" ImageUrl="~/TreeView/drafts.gif" Expanded="True"/>

     

     

     

     

    Please advise.

Back to Top