year and month in treeview

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

year and month in treeview

Post by sal21 »

Please an example for:

myvar MYear=2022

i need in treeview:

YEAR (is a big root)

01-gennaio
02-febbaraio
...
12 dicembre

end when i click on a month expand all days...

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

Re: year and month in treeview

Post by HansV »

You can modify this to your preference:

Code: Select all

    Dim m As Long
    Dim d As Long
    Dim nodRoot As Node
    Dim nodMonth As Node
    With Me.TreeView1
        .LineStyle = tvwRootLines
        .Style = tvwTreelinesPlusMinusText
        Set nodRoot = .Nodes.Add(Text:=MyYear)
        For m = 1 To 12
            Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(m, "00") & "-" & MonthName(m))
            For d = 1 To Day(DateSerial(MyYear, m + 1, 0))
                .Nodes.Add Relative:=nodMonth, _
                    Relationship:=tvwChild, _
                    Text:=Format(DateSerial(MyYear, m, d), "dddd d mmmm yyyy")
            Next d
        Next m
    End With
Best wishes,
Hans

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
15 Sep 2022, 15:10
You can modify this to your preference:

Code: Select all

    Dim m As Long
    Dim d As Long
    Dim nodRoot As Node
    Dim nodMonth As Node
    With Me.TreeView1
        .LineStyle = tvwRootLines
        .Style = tvwTreelinesPlusMinusText
        Set nodRoot = .Nodes.Add(Text:=MyYear)
        For m = 1 To 12
            Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(m, "00") & "-" & MonthName(m))
            For d = 1 To Day(DateSerial(MyYear, m + 1, 0))
                .Nodes.Add Relative:=nodMonth, _
                    Relationship:=tvwChild, _
                    Text:=Format(DateSerial(MyYear, m, d), "dddd d mmmm yyyy")
            Next d
        Next m
    End With
as usual great!

... how to retun value when i clcik on bigroot, subroot, items?

for example store the clicked value in MyVarTXT

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

Re: year and month in treeview

Post by HansV »

Code: Select all

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    Dim MyVarTXT As String
    MyVarTXT = Node.Text
    MsgBox "You clicked on " & MyVarTXT, vbInformation
End Sub
Best wishes,
Hans

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

Re: year and month in treeview

Post by sal21 »

:clapping:
HansV wrote:
15 Sep 2022, 19:47

Code: Select all

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    Dim MyVarTXT As String
    MyVarTXT = Node.Text
    MsgBox "You clicked on " & MyVarTXT, vbInformation
End Sub

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
15 Sep 2022, 19:47

Code: Select all

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    Dim MyVarTXT As String
    MyVarTXT = Node.Text
    MsgBox "You clicked on " & MyVarTXT, vbInformation
End Sub
BRO...
To not permit the edit of item i use for example, for textbox:

Code: Select all


Private Sub Text_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

possible to have the same effect on all nodes in teeview?

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

Re: year and month in treeview

Post by HansV »

Set the LabelEdit property of the TreeView control to 1 - tvwManual.
Best wishes,
Hans

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
16 Sep 2022, 14:35
Set the LabelEdit property of the TreeView control to 1 - tvwManual.
i'm, stupid....
but not have a great experince with treeview

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
15 Sep 2022, 15:10
You can modify this to your preference:

Code: Select all

    Dim m As Long
    Dim d As Long
    Dim nodRoot As Node
    Dim nodMonth As Node
    With Me.TreeView1
        .LineStyle = tvwRootLines
        .Style = tvwTreelinesPlusMinusText
        Set nodRoot = .Nodes.Add(Text:=MyYear)
        For m = 1 To 12
            Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(m, "00") & "-" & MonthName(m))
            For d = 1 To Day(DateSerial(MyYear, m + 1, 0))
                .Nodes.Add Relative:=nodMonth, _
                    Relationship:=tvwChild, _
                    Text:=Format(DateSerial(MyYear, m, d), "dddd d mmmm yyyy")
            Next d
        Next m
    End With
how to assign i icon from imagelist1 during the code fill treeview?
For example for month node index icon =1, and for each days of month index icon =2

note:
i just have set imagelist1 in property of treeview

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

Re: year and month in treeview

Post by HansV »

For the months:

Code: Select all

            Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(m, "00") & "-" & MonthName(m), _
                Image:=1)
and similar for the days
Best wishes,
Hans

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
18 Sep 2022, 18:26
For the months:

Code: Select all

            Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(m, "00") & "-" & MonthName(m), _
                Image:=1)
and similar for the days
opsss.

during the edit of your code, now have:

...
For M = 1 To 12

Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
Relationship:=tvwChild, _
Text:=Format(M, "00") & "-" & UCase(MonthName(M)))

For D = 1 To Day(DateSerial(ANNO, M + 1, 0))
.Nodes.Add Relative:=nodMonth, _
Relationship:=tvwChild, _
Text:=UCase(Format(DateSerial(ANNO, M, D), "dd/mm/yyyy")) & "-" & UCase(Format(DateSerial(ANNO, M, D), "dddd"))

Next D

Next M
...

but not idea to set the icon from imagelist

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

Re: year and month in treeview

Post by HansV »

See my previous reply. You can also use the Key value of the image instead of its index. For example, if you have added an image to your ImageList control with Key:="Month", you can use

Code: Select all

            Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(m, "00") & "-" & UCase(MonthName(m)), _
                Image:="Month")
Best wishes,
Hans

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
18 Sep 2022, 18:58
See my previous reply. You can also use the Key value of the image instead of its index. For example, if you have added an image to your ImageList control with Key:="Month", you can use

Code: Select all

            Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(m, "00") & "-" & UCase(MonthName(m)), _
                Image:="Month")

Code: Select all

    With Me.TreeView1

        .Nodes.Clear
        
        Set Me.TreeView1.ImageList = ImageList1
        
        .LineStyle = tvwRootLines
        .Style = tvwTreelinesPlusMinusText
        Set nodRoot = .Nodes.Add(Text:=ANNO)
        
        For M = 1 To 12
        
        Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                Relationship:=tvwChild, _
                Text:=Format(M, "00") & "-" & UCase(MonthName(M)), _
                Image:="M")
        
            'Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
                                      Relationship:=tvwChild, _
                                      Text:=Format(M, "00") & "-" & UCase(MonthName(M)))
                                      
            For D = 1 To Day(DateSerial(ANNO, M + 1, 0))
                .Nodes.Add Relative:=nodMonth, _
                           Relationship:=tvwChild, _
                           Text:=UCase(Format(DateSerial(ANNO, M, D), "dd/mm/yyyy")) & "-" & UCase(Format(DateSerial(ANNO, M, D), "dddd")), Image:="G"
            
            Next D
            
        Next M

    End With

End Sub
The key are m for month, g for day, but i dont see the icon!

Peraphs i need to set property style in treeview?
You do not have the required permissions to view the files attached to this post.

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

Re: year and month in treeview

Post by HansV »

I hope that speakeasy can help. I don't have VB6, as you know.
Best wishes,
Hans

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
18 Sep 2022, 20:10
I hope that speakeasy can help. I don't have VB6, as you know.
:thankyou:

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

Re: year and month in treeview

Post by sal21 »

HansV wrote:
18 Sep 2022, 20:10
I hope that speakeasy can help. I don't have VB6, as you know.
RESOLVED MY SELF!

For share the solution...

i have comment this lines,
'.LineStyle = tvwRootLines
'.Style = tvwTreelinesPlusMinusText

and set directlly this prperty in ide, and work!

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

Re: year and month in treeview

Post by HansV »

Great!
Best wishes,
Hans

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

Re: year and month in treeview

Post by SpeakEasy »

>RESOLVED MY SELF!

Er ... no you didn't - https://www.tek-tips.com/viewthread.cfm?qid=1818837