Solved

Progress Bar, Tree View & List view controls

Posted on 1998-10-22
17
822 Views
Last Modified: 2008-02-20
Couple of questions but related.

First:  The following code fills a tree view with two nodes, work and home locations.  The whole thing works correctly with one problem.  The progress bar works when you expand the first node. Once you collapse (is that the right term?) the node and expand another node, the progress bar stops working.  It doesn't matter which node you expand first, the progress bar will work.  The progress bar will not work on subsequent node expansions.

2nd problem.  As I said the tree view has two nodes, Home Location and Work Location.  I want to add additional levels beneath each location, called Partner and Child.

the nodes will look something like this:

Home Location
   Cargill
   Transcam
   Inverness
     Partner
     Child
   Dunedin
   Scotland
Work Location
   etc
   etc

Is it possible to add the additional sub nodes?  If so how.

My current code is below.  I have included everything in case some relates to the progress bar problem.

Public strSelectedName As String

Private Sub Form_Load()
    Dim objTreeView As Object, objListImage As Object, nodNew As Node
    Dim prg As Control, sbr As Control
    Dim intI As Integer
    Dim rstHomeLocation As Recordset, rstWorkLocation As Recordset
    Dim db As Database
   
    Set objListImage = Me!FileImages
    Set objTreeView = Me!Treeview1
    Set db = CurrentDb
   
    ' Set TreeView control ImageList property
    objTreeView.ImageList = objListImage.Object
    objTreeView.Sorted = True
   
    ' Add top level node objects to TreeView control
    Set nodNew = objTreeView.Nodes.Add(, , "Home Location", "Home Location", "ManyClosed")
    nodNew.ExpandedImage = "ManyOpen"
   
    Set nodNew = objTreeView.Nodes.Add(, , "Work Location", "Work Location", "ManyClosed")
    nodNew.ExpandedImage = "ManyOpen"
   
    ' Add Location Names to Home Location Node object
    Set rstHomeLocation = db.OpenRecordset("qryTestTreeViewHome")
    rstHomeLocation.MoveFirst
    While Not rstHomeLocation.EOF
        objTreeView.Nodes.Add "Home Location", tvwChild, , rstHomeLocation!resHomeLocation, "OneClosed", "OneOpen"
        rstHomeLocation.MoveNext
    Wend
    rstHomeLocation.Close
   
    ' Add Location Names to Work Location Node object
    Set rstWorkLocation = db.OpenRecordset("qryTestTreeViewWork")
    rstWorkLocation.MoveFirst
    While Not rstWorkLocation.EOF
        objTreeView.Nodes.Add "Work Location", tvwChild, , rstWorkLocation!resWorkLocation, "OneClosed", "OneOpen"
        rstWorkLocation.MoveNext
    Wend
    rstWorkLocation.Close
   
    ' Prepare Progress Bar
    Set prg = Me!ProgressBar
    Set sbr = Me!StatusBar
   
    prg.Left = sbr.Left
    prg.Top = sbr.Top + 30
    prg.Height = sbr.Height - 30
    prg.Width = sbr.Panels(1).Width + 15
   
    'HideSwitchboard
End Sub




Private Sub TreeView1_Collapse(ByVal Node As Object)
    ' Clear existing items when user collapses node object
    Me!ListView.ListItems.Clear
    Me!ListView.HideColumnHeaders = True
    Me!StatusBar.Panels(1).text = ""
    Me!StatusBar.Panels(2).text = ""
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As Object)
    Static intPrevNode As Integer
     
    ' Ignore click on top level nodes
    If Node.Parent Is Nothing Then Exit Sub
   
    ' Ignore click on the currently expanded node
    If intPrevNode = Node.Index Then
        Exit Sub
    Else
        intPrevNode = Node.Index
    End If
   
    DoCmd.Hourglass True
    Select Case Node.Parent.key
        Case "Home Location"
            ExpandHomeLocation Node
        Case "Work Location"
            ExpandWorkLocation Node
    End Select
    DoCmd.Hourglass False
End Sub

Private Sub ExpandHomeLocation(Nodcur As Node)
    Dim db As Database, rs As Recordset, intRecs As Integer
    Dim strhomeLocation As String, strLastName As String, strSQL As String
    Dim itmAdd As ListItem
   
    ' Reset ListView Control
    Me!ListView.ListItems.Clear
    With Me!ListView.ColumnHeaders
        .Clear
        .Add , , "Home Location", 0
        .Add , , "Resident Name", 2500
    End With
    Me!ListView.HideColumnHeaders = False
    strhomeLocation = (Nodcur.text)
   
    ' Create SQL statement used to fill recordset
    Set db = CurrentDb
    strSQL = "SELECT * FROM qryTestListViewHome WHERE (resHomeLocation = """ & strhomeLocation & """);"

    Set rs = db.OpenRecordset(strSQL)
   
    ' Populate the data
    rs.MoveLast
    intRecs = rs.RecordCount
    With Me!ProgressBar
        .Value = 0
        .Visible = True
        .Max = intRecs
    End With
   
    rs.MoveFirst
    While Not rs.EOF
        Set itmAdd = ListView.ListItems.Add()
        itmAdd.text = rs!resHomeLocation
        itmAdd.SubItems(1) = rs!resLastName & ", " & rs!resFirstName
        Me!ProgressBar.Value = Me!ProgressBar.Value + 1
        rs.MoveNext
    Wend
    rs.Close
    Me!ProgressBar.Visible = False
       
    ' Set the status bar text
    Me!StatusBar.Panels(1).text = strhomeLocation
    Me!StatusBar.Panels(2).text = Trim$(CStr(intRecs)) & " Residents"
End Sub

Sub ExpandWorkLocation(Nodcur As Node)
    Dim db As Database, rs As Recordset, intRecs As Integer
    Dim strworkLocation As String, strLastName As String, strSQL As String
    Dim itmAdd As ListItem
   
    ' Reset ListView Control
    Me!ListView.ListItems.Clear
    With Me!ListView.ColumnHeaders
        .Clear
        .Add , , "Work Location", 0
        .Add , , "Resident Name", 2500
    End With
    Me!ListView.HideColumnHeaders = False
    strworkLocation = (Nodcur.text)
   
    ' Create SQL statement used to fill recordset
    Set db = CurrentDb
    strSQL = "SELECT * FROM qryTestListViewWork WHERE (resworkLocation = """ & strworkLocation & """);"

    Set rs = db.OpenRecordset(strSQL)
     
    ' Populate the data
    rs.MoveLast
    intRecs = rs.RecordCount
    With Me!ProgressBar
        .Value = 0
        .Visible = True
        .Max = intRecs
    End With
   
    rs.MoveFirst
    While Not rs.EOF
        Set itmAdd = ListView.ListItems.Add()
        itmAdd.text = rs!resWorkLocation
        itmAdd.SubItems(1) = rs!resLastName & ", " & rs!resFirstName
        Me!ProgressBar.Value = Me!ProgressBar.Value + 1
        rs.MoveNext
    Wend
    rs.Close
    Me!ProgressBar.Visible = False
       
    ' Set the status bar text
    Me!StatusBar.Panels(1).text = strworkLocation
    Me!StatusBar.Panels(2).text = Trim$(CStr(intRecs)) & " Residents"
End Sub


So why doesn't the progress bar work correctly and what changes are needed to include the extra levels beneath the nodes.

The code above is taken from a sample database I was given, and I modified it.  What does OneOpen, OneClosed and ManyClosed do?

Need a good answer for this one.  Also an explanation on each line of code you add to mine, for it to be of use to me.  500 points to the answer and an A is guaranteed.  I can guarantee an A because I won't accept an answer unless it's worth that.

Thanks for your help

sarah
0
Comment
Question by:sarahgal
  • 5
  • 4
  • 3
  • +3
17 Comments
 

Author Comment

by:sarahgal
ID: 1966285
Edited text of question
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1966286
If you want you may mail me your project and I will have a look at it. Difficult to make a 100% answer when you don't have the data... (EMail: Trygve@Omega.No)
0
 
LVL 5

Expert Comment

by:chewhoung
ID: 1966287
Also to chewhoung@yahoo.com
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1966288
Not to me, I can't stand the pressure :)
0
 
LVL 3

Expert Comment

by:BGillham
ID: 1966289
First of all get rid of DAO, ADO is a much flatter & simpler data model. (This is only a suggestion). As for your Progress bar it appears from your code (and I do not know what Progress Bar you are using) that you are adding 1 (one) to the value and not a percentage of the total record count. If you had exactly 100 records your progress bar would work. "OneOpen" etc. indicates siblings of the selected node.
Hope this helps
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1966290
BGillham, that's because she has set the max to intrecs so it will always reflect the number of records and move up one for each record.
0
 
LVL 3

Expert Comment

by:BGillham
ID: 1966291
In addition to my answer here is a gem that I have learned the hard way. NEVER use: While NOT EOF. Do a MoveLast (you MUST do this) and a RecordCount and then do For X = 1 to RecordCount. It is then easier to calculate the Progress Bar and loop through your records. This way is approx. 40% faster than the EOF method. (Each loop of the EOF method does a check for EOF - very slow)
0
 

Author Comment

by:sarahgal
ID: 1966292
BGillham what about the nodes?

Sorry, but will reopen the question for someone else to answer
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:sarahgal
ID: 1966293
trygve, will email the database to you as you commented first.  Perhaps you should click "answer" the question to hold it in the meantime.

Sarah

0
 
LVL 12

Accepted Solution

by:
Trygve earned 500 total points
ID: 1966294
As you wish. I will start looking at it immediately
0
 

Expert Comment

by:Booh
ID: 1966295
I had checked your listing and what would like to say is that:

1. The above code had been designed only for two Sections "Home Location" and "Work Location". Even function for treeView1.Collapse had been developed for these sections only. You can see it.

2. To have the possibility to create the Node in whatever location you want you should to create universal code for that purpose. This code should check the Current position in the Tree and make some action accordingly. You can describe your Nodes as an object with some structured type and plase information you need there. And then restore it when you click on Node. But it is technical question.

3. "OneOpen", "ManyOpen" it is not Siblings as you were suggested in the Comments before. These are the pictures placed in Me!FileImages and which are assigned to the Node in particular situation.


Why I am so sure about all this because I had a lot of work with TreeView Control(using whole functionality of that Control and OOP, what allow me to place, store, handle the Tree and information there in a way I want).

If you have any question, do  not hesitate.

Best wishes,
Sergey Basharin
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1966296
I don't think "holding" an answer is in the spirit of EE. The question should remain open until it is satisfactorily answered. If someone answers before Trygve they should get the points. Anyone agree?
0
 

Expert Comment

by:Booh
ID: 1966297
I don't care.
I am just interested in resolving of the problem and to give some constructive advice to person who need it. That is count.
Best wishes,
Sergey.
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1966298
Helicopter: I agree and disagree. I have had disputes like this before with other participants on E-E. We argumented back and forth a lot and could not agree (at that time I was the one complaining that the other experts had acted nonethical). That argument was based on the fact that I felt that the other expert, and others, where jumping into a thread where I, and others, had worked with the questioner and suddenly posted an answer with more or less nothing new. When the questioner had gotten all the answer he/she accepted without checking who had locked the question. That was really irritating.

As for the spirit of E-E, I think the meaning is that the questioner is the one in charge. So it does not really matter what we, the experts, think as long as the questioner is happy.

This time I am the one "holding" the question, and I am would not have done it if it had not been for the fact that the questioner proposed it. I have to add that I was the first one to post a comment on the question so I have not tried to take anyones place as the screen.CurrentExpert so to speak.

I must say though that once you start working on a complexe problem it is kind of rewarding to see that the questioner trusts you enough to stay with you till the answer is found. If I at any point see that I will not be able to solve the problem, I will post or mail a request for the questioner to reopen the question. There are so many new question each day now, that I don't think it should be necessary to have arguments over them.

For the record.
1) The problem with the disapearing progress bar is related to the statusbar control. Once you set the status text it comes in the way of the progress bar so that this cannot be viewed. To show the bar again the status bar texts has to be set to ""
2) Adding more levels to the tree demands each item that is to be used as a "parent" to have a key/ID so the line inserting the locations has to be rewritten to something like  
Set nodNew = objTreeView.Nodes.Add("Home Location", tvwChild, "Home" & rstHomeLocation!resHomeLocation, rstHomeLocation!resHomeLocation, "ManyClosed")
nodNew.ExpandedImage = "ManyOpen"
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1966299
I have mailed my attempt at fixing the problems. Let me know if you have received the mail.
0
 

Author Comment

by:sarahgal
ID: 1966300
Trygve,

Thanks I received the email.  I tested the new code last night and it works just fine.  The solution you provide is excellent and just what I was looking for.

Thank you very much.

Sarah

0
 
LVL 12

Expert Comment

by:Trygve
ID: 1966301
Just give me a hint if you need any input on what I have done or any adjustments ( within reasonable limits, ;-) )

Have a very nice day !
Trygve
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now