morrisette
asked on
Code for Windows Explorer type tree view wanted
Hi
I am trying to create a tree view of departments in a company within each department there are Workcentres.
When I click on a work centre I want the employees to be displayed as files would be in Windows explorer if I clicked on a sub folder. I will be using an Employee Access table which holds all employee details. I am using ADO and VB6. Currently I am selecting the employees from a dropdown list, but this does not categorise employees in workcentres which would make it easier for the user to browse.
Can the experts help?
Thanks
morrisette
I am trying to create a tree view of departments in a company within each department there are Workcentres.
When I click on a work centre I want the employees to be displayed as files would be in Windows explorer if I clicked on a sub folder. I will be using an Employee Access table which holds all employee details. I am using ADO and VB6. Currently I am selecting the employees from a dropdown list, but this does not categorise employees in workcentres which would make it easier for the user to browse.
Can the experts help?
Thanks
morrisette
ASKER
Thanks mdougan
I will try this and let you know. it looks very good.
morrisette
I will try this and let you know. it looks very good.
morrisette
Depending on how many departments and workcenters you have, if it seems to take a long time to load the tree let me know, I have a routine that can be used to lock the treeview window so that it does not update after each node is added which really slows down the loading. You wont notice it if you're just adding 50 or 100 nodes, but if you have several hundred, you might.
morrisette,
here is a link to a class sample for treeview that may also be helpful...
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=34439
here is a link to a class sample for treeview that may also be helpful...
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=34439
ASKER
Thanks magoo2. I will check this out
morrisette
morrisette
ASKER
Hi mdougan
could I have the routine to lock the tree during update, please.
morrisette
could I have the routine to lock the tree during update, please.
morrisette
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi morrisette,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept mdougan's comment(s) as an answer.
morrisette, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept mdougan's comment(s) as an answer.
morrisette, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
per recommendation
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
The query for filling the treeview should look something like this:
Select D.DepartmentID, D.DepartmentName,
W.WorkCenterID, W.WorkCenterName
From Department D, WorkCenter W
Where W.DepartmentID = D.DepartmentID
Order by D.DepartmentName, W.WorkCenterName
Then When filling the TreeView, you code might look like this:
Dim xNode As Node
Dim i As Long
Dim lDeptID as long
On Error Resume Next
Screen.MousePointer = vbHourglass
' clear out the tree
tvwObjects.Nodes.Clear
' set the imagelist to an image list on the form
Set tvwObjects.ImageList = Nothing
Set tvwObjects.ImageList = imlObjects
' assuming that you've already opened the recordset
While Not RS.EOF
' if are now on a new department, add the department node
if lDeptID <> RS("departmentID").Value Then
Set xNode = tvwObjects.Nodes.Add , , "D" & RS("departmentid").Value, RS("departmentname").Value
lDeptID = RS("departmentID").Value
End if
' now, add the workcenter node don't worry about setting the relationships yet
Set xNode = tvwObjects.Nodes.Add , , "W" & RS("workcenterid").Value, RS("workcentername").Value
xNode.Tag = "D" & RS("departmentID").Value
RS.MoveNext
Wend
' now, go through and set the hierarchical relationships
For Each xNode In tvwObjects.Nodes
sParent = xNode.Tag
If Len(xNode.Tag) > 0 Then ' Don't try and reparent the Departments!
Set xNode.Parent = tvwObjects.Nodes(xNode.Tag
End If
Next
' these numbers correspond to folder and leaf icons respectively
' so, set the appropriate icons
For Each xNode In tvwObjects.Nodes
If xNode.Children > 0 Then
xNode.Image = 1
Else
xNode.Image = 2
End If
Next
tvwObjects.Refresh
Screen.MousePointer = vbDefault
Then, in the node_click event of the tree, you can use the tvwObjects.SelectedNode.Ke