Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Make treeview node bold

I have a treeview that i've defined in my Master page. I build the treeview dynamically in the whatever.aspx.

Tree looks like this:
>node1
>node2
>node3
  >subnode3_1
  >subnode3_2

I want to the fonts for the main nodes to be bold. I tried these :
  1. Font-Bold="true"  makes nodes and SUBnodes bold
  2. RootNodeStyle-Font-Bold="true"  : makes "node3" bold BUT doesnt makde node1 and node2 bold. It should since they're main nodes too..no?

  3. NodeStyle-Font-Bold="true" : i think it made all of the nodes and subnodes bold

Tried a combination and didnt work. Wanted to do it dynamically in the code behind but i didnt see "attributes" for the treenode:
treeNode = New TreeNode(....)
SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

let me try.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hmmm...this isnt working...

1. I imported :  Imorts System.Drawing
2. I cant do what Jaime has because I cant have "New Font (Treeview1.Font,Font.Bold)". New Font cant take "treeview1.Font" as one of the parameters. It has to be a font family name.

I looked at emoreau's example and tried webTubbs's example as well but I dont see .BackColor or .NodeFont.

I tried this : http://www.vb-helper.com/howto_net_font_samples.html
and created a new font:  Dim new_font As New Font("Something", 8, FontStyle.Bold)

**But now what..I have the treeNode like this:
  treeNode = New TreeNode("whatever")
But I dont know how to assign the font to the treeNode. I did " treenode. " but I dont see a Font or "Something" in intellisense...
>>I looked at emoreau's example and tried webTubbs's example as well but I dont see .BackColor or .NodeFont.
Are you working with Compact Framework / Windows Mobile ?
no, this is asp.net/VB.net (not my forms C# app).

This is what I have so far...
 Dim treeNode As TreeNode
        Dim treeSubNode As TreeNode
        Dim treeSubNode2 As TreeNode
        Dim da As DataRow
        Dim daNode As DataRow
        '  Dim p As FontStyle = FontStyle.Bold
        Dim new_font As New Font("Something", 8, FontStyle.Bold)
 
 
        If userTabsTable.Rows.Count > 0 Then 'if user has tabs setup in taborder table.
 
 
            'build the nodes. Localize node text
            For Each da In userTabsTable.Rows
                treeNode = New TreeNode(...)
  ....

Open in new window

And I have VS2005, Professional Edtion.

This works Master.tvTabsms.Font.Bold = True
But that makes ALL the nodes, even the subnodes bold/
Now I see it:
    With (Master.mytreeview)
       End With

I was doing : with (master.mytreeview.nodes)
                      End With

Let me play around with it and see how I can use that with my "treeNode" variable
No, I cant get this to work. Even tried following Eric's example but I get "expression does not produce a value".

This cant be that hard!

        With Master.tvTabsms
 
            If userTabsTable.Rows.Count > 0 Then 'if user has tabs setup in taborder table.
 
 
                'build the nodes. Localize node text
                For Each da In userTabsTable.Rows
                    treeNode = New TreeNode(CStr(HttpContext.GetLocalResourceObject("/SideMenuTree", "tv" & da(1).ToString.Trim & ".Text")))
 
                    Dim nodeParent As TreeNode
                    nodeParent = Master.tvTabsms.Nodes.Add(New TreeNode(CStr(HttpContext.GetLocalResourceObject("/SideMenuTree", "tv" & da(1).ToString.Trim & ".Text"))))  '**** get an error here
 
 
 
 
                    If da(2).ToString.Trim = "X" OrElse da(2).ToString.Trim = "XX" Then 'build the subnode
                        For Each daNode In userTabsSubNodeTable.Rows
                            treeSubNode = New TreeNode(daNode(0).ToString)
                            treeNode.ChildNodes.Add(treeSubNode)
                            If da(2).ToString.Trim = "XX" And daNode(1).ToString.Trim <> String.Empty Then
                                treeSubNode2 = New TreeNode(daNode(1).ToString)
                                treeSubNode.ChildNodes.Add(treeSubNode2)
                            End If
 
 
 
                        Next
                        Master.tvTabsms.Nodes.Add(treeNode)
                    Else
 
                        ' treeNode = New TreeNode(CStr(HttpContext.GetLocalResourceObject("/SideMenuTree", "tv" & da(1).ToString.Trim & ".Text")))
                        Master.tvTabsms.Nodes.Add(treeNode)
                    End If
 
 
                Next
 
            End If
        End With

Open in new window

tried this as well but i dont see a ".NodeFont"

http://p2p.wrox.com/topic.asp?TOPIC_ID=44516
If I do this, I can get the main nodes to change color to Red:
 treeNode = New TreeNode("<font color = red>" & CStr(HttpContext.GetLocalResourceObject("/SideMenuTree", "tv" & da(1).ToString.Trim & ".Text")) & "</font>")

I found it here: http://forums.devx.com/showthread.php?t=153246

Now need to make it bold
Sorry everyone, I made it work like this:

  treeNode = New TreeNode("<b>" & CStr(HttpContext.GetLocalResourceObject("/SideMenuTree", "tv" & da(1).ToString.Trim & ".Text")) & "</b>")

Thanks