Solved

Treeview - setting node font / bold

Posted on 2012-04-02
9
887 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 31

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 31

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
 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

624 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