Treeview populating a text box

nighthawk
02-06-2002, 01:19 PM
I have a tree view with that has three levels, Year, Month and Day.

Once the user has selected the day I want a textbox to fill with data from a class but I am unsure how to go about doing that.
If anyone knows or knows of an example I would be ever so grateful.

Flyguy
02-06-2002, 01:20 PM
Uh, what do you mean with "data from a class"?

When the day is click you have to month and the year?

nighthawk
02-06-2002, 02:31 PM
I am populating my treeview from a database. However we are running the database through classes. So I have an object called Weekly Report.

mvarDate = oWeeklyReport.Date

I then split that date using the Right$, Left$ stuff and come up with:

mvarYear
mvarMonth
mvarDate

The Year is the top node when it is selected (clicked on) the months are shown.

When the month is selected the days are shown.

When the day is selected I want my text box text to = oWeeklyReport.Content.

Here's a little snippet of the code to populate my treeview:

If PrevYear <> year Then
Set NodeYear = treReport.Nodes.Add(, , "Y" & (year), (year), 1, 2)
Set NodeMonth = treReport.Nodes.Add(NodeYear, tvwChild, "M" & (year), (month), 1, 2)
Set NodeDay = treReport.Nodes.Add(NodeMonth, tvwChild, (year) & (month), (cday), 3, 4)
PrevYear = year
PrevMonth = month
PrevDay = cday
ElseIf PrevYear = year And PrevMonth <> month Then
Set NodeMonth = treReport.Nodes.Add(NodeYear, tvwChild, "M" & (year) & (month), (month), 1, 2)
Set NodeDay = treReport.Nodes.Add(NodeMonth, tvwChild, "D" & (year) & (month) & (cday), (cday), 3, 4)
PrevMonth = month
PrevDay = cday
ElseIf PrevYear = year And PrevMonth = month And PrevDay <> cday Then
Set NodeDay = treReport.Nodes.Add(NodeMonth, tvwChild, "D" & (year) & (month) & (cday), (cday), 3, 4)
PrevDay = cday
ElseIf PrevYear = year And PrevMonth = month And PrevDay = cday Then

Banjo
02-06-2002, 03:58 PM
Is this the code to populate the treeview1 or the code to display the text linked to a specific node?

If you are just selecting from an already built tree then perhaps something like this:
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If Node.Parent Is Nothing Then
year = Node.Key
Else
If Node.Parent.Parent Is Nothing Then
year = Node.Parent.Key
month = Node.Key
Else
year = Node.Parent.Parent.Key
month = Node.Parent.Key
day = Node.Key
End If
End If

' now look up the text associated with year, month and day
End Sub
If you are building the tree then try this:
Private Sub AddReport(year As Long, month As Integer, day As Integer)
Dim nYear As Node, nMonth As Node, nDay As Node

' Search for the year
If treReport.Nodes.Count = 0 Then
Set nYear = Nothing
Else
Set nYear = treReport.Nodes(1)
End If
Do Until nYear Is Nothing
If n.Key = year Then Exit Do
Set nYear = nYear.Next
Loop
If nYear Is Nothing Then
' not found
Set nYear = treReport.Nodes.Add(,, year)
End If

Set nMonth = nYear.Child
Do Until nMonth Is Nothing
If nMonth.Key = month then Exit Do
Set nMonth = nMonth.Next
Loop
If nMonth Is Nothing Then
Set nMonth = treReport.Add nYear.Key, tvwChild, month
End If

Set nDay = nMonth.Child
Do Until nDay Is Nothing
If nDay.Key = day then Exit Do
Set nDay = nDay.Next
Loop
If nDay Is Nothing Then
Set nDay = treReport.Add nMonth.Key, tvwChild, day
End If

Set nYear = Nothing
Set nMonth = Nothing
Set nDay = Nothing
End Sub
Or if you don't need to add them randomly:
Private Sub FillTree()
Dim nYear As Node, lYear As Long
Dim nMonth As Node, iMonth As Long
Dim nDay As Node, iDay As Long

For lYear = firstyear To LastYear
Set nYear = treReport.Nodes.Add , , iYear
For iMonth = 1 To 12
Set nMonth = treReport.nodes.Add lYear, tvwChild, iMonth
For iDay = 1 To maxDaysInMonth
Set nDay = treReport.Node.Add iMonth, tvwChild, iDay
Next iDay
Next iMonth
Next lYear

Set nYear = Nothing
Set nMonth = Nothing
Set nDay = Nothing
End Sub
I'll leave it as an exercise for you to work out firstyear, lastyear and the correct number of days in each month.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum