year and month in treeview
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
year and month in treeview
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...
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...
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: year and month in treeview
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
Hans
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
Re: year and month in treeview
as usual great!HansV wrote: ↑15 Sep 2022, 15:10You 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 retun value when i clcik on bigroot, subroot, items?
for example store the clicked value in MyVarTXT
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: year and month in treeview
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
Hans
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
Re: year and month in treeview
HansV wrote: ↑15 Sep 2022, 19:47Code: 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
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
Re: year and month in treeview
BRO...HansV wrote: ↑15 Sep 2022, 19:47Code: 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
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
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: year and month in treeview
Set the LabelEdit property of the TreeView control to 1 - tvwManual.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
Re: year and month in treeview
how to assign i icon from imagelist1 during the code fill treeview?HansV wrote: ↑15 Sep 2022, 15:10You 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
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
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: year and month in treeview
For the months:
and similar for the days
Code: Select all
Set nodMonth = .Nodes.Add(Relative:=nodRoot, _
Relationship:=tvwChild, _
Text:=Format(m, "00") & "-" & MonthName(m), _
Image:=1)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
Re: year and month in treeview
opsss.HansV wrote: ↑18 Sep 2022, 18:26For the months:
and similar for the daysCode: Select all
Set nodMonth = .Nodes.Add(Relative:=nodRoot, _ Relationship:=tvwChild, _ Text:=Format(m, "00") & "-" & MonthName(m), _ Image:=1)
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
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: year and month in treeview
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
Hans
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
Re: year and month in treeview
HansV wrote: ↑18 Sep 2022, 18:58See 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
Peraphs i need to set property style in treeview?
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: year and month in treeview
I hope that speakeasy can help. I don't have VB6, as you know.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4377
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 4StarLounger
- Posts: 574
- Joined: 27 Jun 2021, 10:46