Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Treeview populating a text box


Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2002, 01:19 PM
nighthawk nighthawk is offline
Junior Contributor
 
Join Date: Jun 2001
Location: WV
Posts: 280
Question Treeview populating a text box


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.
Reply With Quote
  #2  
Old 02-06-2002, 01:20 PM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,884
Default

Uh, what do you mean with "data from a class"?

When the day is click you have to month and the year?
Reply With Quote
  #3  
Old 02-06-2002, 02:31 PM
nighthawk nighthawk is offline
Junior Contributor
 
Join Date: Jun 2001
Location: WV
Posts: 280
Default

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
Reply With Quote
  #4  
Old 02-06-2002, 03:58 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default

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:
Code:
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:
Code:
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:
Code:
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.
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->