Solved

Treeview - setting node font / bold

Posted on 2012-04-02
9
843 Views
Last Modified: 2012-04-02
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.
0
Comment
Question by:slobber72
  • 4
  • 3
  • 2
9 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37794857
Nodes do not have a Font property. They do however have a Bold property... ;)
0
 

Author Comment

by:slobber72
ID: 37795340
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
0
 
LVL 29

Expert Comment

by:gowflow
ID: 37795357
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
0
 
LVL 29

Expert Comment

by:gowflow
ID: 37795367
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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:slobber72
ID: 37795392
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 ?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37795419
No - it works fine for me. Is there a reason why you are passing the node As Object rather than As Node?
0
 

Author Comment

by:slobber72
ID: 37795483
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
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 37795528
Can you replace your Treeview control version 5 with version 6? I don't have version 5, which is what you appear to be using, so the treeview simply gets removed. This may be part of the problem, since you also have a reference to version 6 of the common controls.

When I do that, the code works - see attached version.
Menu-Documentation-V1.0---Copy.xlsm
0
 

Author Comment

by:slobber72
ID: 37795569
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
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now