Link to home
Start Free TrialLog in
Avatar of slobber72
slobber72

asked on

Treeview - setting node font / bold

Hi there,

I am trying to compare a node key in my treeview control (Excel 2010) to a value in a range. If the two values match, then make the node bold.

I am using the following piece of code:

Private Sub Highlight_Tree(ByVal highlight_node As Object)
' Parentnode previously declared as node - had to change to avoid type mismatch error.
Dim row As Range
Dim rngcomments As Range
Dim wkscomments As Worksheet
Dim n As Object
Set wkscomments = ThisWorkbook.Worksheets("Comments")
Set rngcomments = wkscomments.Range("Comments")

        Do Until highlight_node Is Nothing
            For Each row In rngcomments.Rows
                Debug.Print row.Columns(1).Value, highlight_node.Key
                If row.Columns(1).Value = highlight_node.Key Then
                    With highlight_node.Font
                        .Bold = True
                    End With
                    Exit For
                End If
            Next row
            
            Highlight_Tree highlight_node.Child
            Set highlight_node = highlight_node.Next
        Loop
End Sub

Open in new window


I works all the way up to setting the With highlight_node.Font property, when I get the error:
Object doesn't support this property or method.

Can anyone give me a push on this one ?

Thanks and regards,

Craig.
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Nodes do not have a Font property. They do however have a Bold property... ;)
Avatar of slobber72
slobber72

ASKER

Hi rorys,

Well I changed my code but I'm still getting the same error.

Do Until highlight_node Is Nothing
            For Each row In rngcomments.Rows
                Debug.Print row.Columns(1).Value, highlight_node.Key
                If row.Columns(1).Value = highlight_node.Key Then
                    highlight_node.Bold = True
                    Exit For
                End If
            Next row
            Highlight_Tree highlight_node.Child
            Set highlight_node = highlight_node.Next
        Loop

Open in new window


The line "highlight_node.Bold = True" is where the error is occurring...

Any thoughts ? I don't understand when to use with... for each.... etc with regards to properties and methods.

Cheers,

Craig
Seeing no response from asker and not for points just to clarify, rorya meant for you to
replace this
With highlight_node.Font
     .Bold = True
End With

by this
With highlight_node
     .Bold = True
End With

gowflow
Just noticed that we posted at the same time did not see your post first.

I suggest you simply remove from your original code the .Font and give it a try.
gowflow
Ok - tried that but still the same error.

I am passing the treeview.nodes(1) parameter to the highlight_node procedure .

Would there be an issue here with passing NODES to a procedure and then trying to change the NODE.bold property ?
No - it works fine for me. Is there a reason why you are passing the node As Object rather than As Node?
Yes - setting

(highlight_node as node)

gives a "type mismatch" error when passing treeview.nodes(1) to the procedure.

setting it to object eliminated the error. But I can't get this to work at all. I have attached a copy of the entire spreadsheet. Maybe I am missing a reference ? This is driving me crazy.
Menu-Documentation-V1.0---Copy.xlsm
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland 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
Thank you rorys.

I thought  - I really thought I had a version 6 treeview control. And I never thought to look at that.

This is a great relief.

Cheers,
Craig