COLLAPSE and EXPAND treeview

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

COLLAPSE and EXPAND treeview

Post by sal21 »

Code: Select all

...
 TIPO_STRUTT = Me.LSTRUTT1.Caption
    With Me.TreeView1
        .Nodes.Item(TIPO_STRUTT).Expanded = True
    End With
...
collaps?

User avatar
HansV
Administrator
Posts: 78235
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: COLLAPSE and EXPAND treeview

Post by HansV »

Perhaps

.Expanded = False
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: COLLAPSE and EXPAND treeview

Post by sal21 »

HansV wrote:
19 Jul 2021, 15:25
Perhaps

.Expanded = False
im stupid!

but remember the old code "click unclick", on the same button, i remember only you use a boolean factor....
if yes, how to, now?

peraph resolved my self....(?!)

Code: Select all

...
Static TIP As Boolean
    TIPO_STRUTT = Me.LSTRUTT1.Caption
    With Me.TreeView1
        If TIP Then
            .Nodes.Item(TIPO_STRUTT).Expanded = False
            TIP = False
        Else
            .Nodes.Item(TIPO_STRUTT).Expanded = True
            TIP = True
        End If
    End With
...

User avatar
HansV
Administrator
Posts: 78235
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: COLLAPSE and EXPAND treeview

Post by HansV »

Did it work?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: COLLAPSE and EXPAND treeview

Post by sal21 »

HansV wrote:
19 Jul 2021, 19:13
Did it work?
yes...

User avatar
HansV
Administrator
Posts: 78235
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: COLLAPSE and EXPAND treeview

Post by HansV »

:thumbup:
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: COLLAPSE and EXPAND treeview

Post by SpeakEasy »

Given you are simply toggling the state, and then just using TIP to track the state of .expanded, you can simplify your code:

Code: Select all

    TIPO_STRUTT = Me.LSTRUTT1.Caption
    With Me.TreeView1.Nodes.Item(TIPO_STRUTT)
        .Expanded = Not  .Expanded  
    End With