Solved

Treeview - setting node font / bold

Posted on 2012-04-02
9
845 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
After updating data my Excel graphs are showing too many dates 8 33
Excel 2016 - Black cell borders 11 28
splitting text of cell to columns 14 24
increment numbers by 10 11 31
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

861 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

23 Experts available now in Live!

Get 1:1 Help Now