tree view list refresh

I

iccsi

I would like to know how can I refresh my tree view if I add a record
to the table?
Should I delete whole tree and re create nodes or there is away to
refresh the node I added?

Your information is great appreciated,
 
D

DStegon via AccessMonster.com

ReGen the treeview. Have all the code that created the treeviw in functions
and when ever a node is added to the tree, call the function (or sub) that
fills the tree. it is the easiest way and unless there is an insane amount
of data in the tree should take next to no time at all. You can set a
variable that saves the node placement and then after the tree is redrawn
choose that node.
 
I

inungh

ReGen the treeview.  Have all the code that created the treeviw in functions
and when ever a node is added to the tree, call the function (or sub) that
fills the tree.  it is the easiest way and unless there is an insane amount
of data in the tree should take next to no time at all.  You can set a
variable that saves the node placement and then after the tree is redrawn
choose that node.

Thanks for the message,
if I ReGen the the nodes, will it double the nodes?
Should I remove the nodes before ReGen?

Thanks again,
 
D

DStegon via AccessMonster.com

Ya.. delete all nodes and then Regenerate the entire tree. Especially if you
have unique key values the routine will error when it tries to add a key that
has already been added.
ReGen the treeview.  Have all the code that created the treeviw in functions
and when ever a node is added to the tree, call the function (or sub) that
[quoted text clipped - 14 lines]

Thanks for the message,
if I ReGen the the nodes, will it double the nodes?
Should I remove the nodes before ReGen?

Thanks again,
 
D

Dale Fye

personally, I prefer to just add the new node, but the challenge can be
getting it in the correct order with the other nodes at its level within the
same branch.

So, depending on the number of nodes in the tree, I will occassionally
delete all of the nodes that belong to the new nodes parent node, then re-add
all of those children (and there progeny).
 
I

inungh

Ya.. delete all nodes and then Regenerate the entire tree.  Especially if you
have unique key values the routine will error when it tries to add a key that
has already been added.

inunghwrote:
ReGen the treeview.  Have all the code that created the treeviw in functions
and when ever a node is added to the tree, call the function (or sub) that
[quoted text clipped - 14 lines]
Thanks for the message,
if I ReGen the the nodes, will it double the nodes?
Should I remove the nodes before ReGen?
Thanks again,

Thanks again,
Can you please give one example to delete or remove all nodes from the
tree view list?

Thanks millions,
 
D

DStegon via AccessMonster.com

Sure... sorry..

if you dim tv (you what ever you want to call it) as a treeview control then
set tv to your treeview control on the form, you can clear the tree with .
clear

Public WithEvents tv As TreeView
Set tv = Me.TreeView1.Object (treeview1 is your treeview control on the form)
tv.Nodes.Clear

Sorry for not including that previously.
Ya.. delete all nodes and then Regenerate the entire tree.  Especially if you
have unique key values the routine will error when it tries to add a key that
[quoted text clipped - 19 lines]

Thanks again,
Can you please give one example to delete or remove all nodes from the
tree view list?

Thanks millions,
 
I

inungh

Sure... sorry..

if you dim tv (you what ever you want to call it) as a treeview control then
set tv to your treeview control on the form, you can clear the tree with ..
clear

Public WithEvents tv As TreeView
Set tv = Me.TreeView1.Object (treeview1 is your treeview control on theform)
tv.Nodes.Clear

Sorry for not including that previously.

inunghwrote:
Ya.. delete all nodes and then Regenerate the entire tree.  Especially if you
have unique key values the routine will error when it tries to add a key that
[quoted text clipped - 19 lines]
Thanks again,
Can you please give one example to delete or remove all nodes from the
tree view list?
Thanks millions,

Thanks millions,
Can you please help me the code to expand the tree view on form open?
Thanks again,
 
D

DStegon via AccessMonster.com

inungh said:
Thanks millions,
Can you please help me the code to expand the tree view on form open?
Thanks again,

Not sure what you want here but here is a treeview fill that I posted for
someone else. Hope it helps. You can read through the code and place your
tables and queries as needed and field names... etc

THis is essentially a form with just a TreeView control placed on it.

Option Compare Database
Option Explicit
Public WithEvents TrVw As TreeView

Private Sub Form_Load()

Set TrVw = Me.TreeView0.Object
PopulateTree1

End Sub

Private Sub PopulateTree1()
'this will popluate the names
Dim EmplID As Long
Dim rst As New ADODB.Recordset
Dim nod As Node
Dim nod2 As Node

Set nod = TrVw.Nodes.Add(, , "TrSch", "Training")

nod.EnsureVisible
nod.Expanded = True

Set nod2 = TrVw.Nodes.Add(nod.Key, tvwChild, CStr("T1"), "Title" & "
" & "Taken" & " " & "Due")

'This will only give you employees that actually have a training record
With rst
.Open "SELECT DISTINCTROW Employees.EmployeeID, Employees.LastName,
Employees.FirstName " & _
"FROM Employees INNER JOIN [employee training] ON Employees.EmployeeID =
[employee training].Employee_ID " & _
"ORDER BY Employees.LastName;", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
Do Until .EOF
EmplID = !EmployeeID
With TrVw
'the node is added as Relative, Relation,Key,Text, image (not
using here)
Set nod2 = .Nodes.Add(nod.Key, tvwChild, CStr("E" & rst!
EmployeeID), rst!LastName & ", " & rst!FirstName)
PopulateTree2 EmplID, CStr("E" & rst!EmployeeID)
nod2.Expanded = True
End With
.MoveNext
Loop
End With

End Sub

Private Sub PopulateTree2(EmployeeID As Long, NodKey As String)
'this will populate the training

Dim rst As New ADODB.Recordset

With rst
.Open "SELECT [employee training].Employee_ID, [employee training].
Trng_ID, [employee training].Taken, [employee training].Due, Training.Title "
& _
"FROM [employee training] INNER JOIN Training ON [employee training].
Trng_ID = Training.Training_ID " & _
"WHERE ((([employee training].Employee_ID)=" & EmployeeID & "));",
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do Until .EOF
With TrVw
.Nodes.Add NodKey, tvwChild, "", rst!Title & " " &
(Nz(rst!Taken, "-")) & " " & (Nz(rst!Due, "-"))
'no key need because there are no relationships below this
level to have a relation with
End With
.MoveNext
Loop
.Close
End With

End Sub

Code end ******************************
 
I

inungh

inunghwrote:
Thanks millions,
Can you please help me the code to expand the tree view on form open?
Thanks again,

Not sure what you want here but here is a treeview fill that I posted for
someone else.  Hope it helps.  You can read through the code and place your
tables and queries as needed and field names... etc

THis is essentially a form with just a TreeView control placed on it.

Option Compare Database
Option Explicit
Public WithEvents TrVw As TreeView

Private Sub Form_Load()

Set TrVw = Me.TreeView0.Object
PopulateTree1

End Sub

Private Sub PopulateTree1()
'this will popluate the names
Dim EmplID As Long
Dim rst As New ADODB.Recordset
Dim nod As Node
Dim nod2 As Node

Set nod = TrVw.Nodes.Add(, , "TrSch", "Training")

nod.EnsureVisible
nod.Expanded = True

Set nod2 = TrVw.Nodes.Add(nod.Key, tvwChild, CStr("T1"), "Title" & "
" & "Taken" & "          " & "Due")

'This will only give you employees that actually have a training record
With rst
   .Open "SELECT DISTINCTROW Employees.EmployeeID, Employees.LastName,
Employees.FirstName " & _
   "FROM Employees INNER JOIN [employee training] ON Employees.EmployeeID =
[employee training].Employee_ID " & _
   "ORDER BY Employees.LastName;", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
   Do Until .EOF
       EmplID = !EmployeeID
       With TrVw
           'the node is added as Relative, Relation,Key,Text,image (not
using here)
           Set nod2 = .Nodes.Add(nod.Key, tvwChild, CStr("E" & rst!
EmployeeID), rst!LastName & ", " & rst!FirstName)
           PopulateTree2 EmplID, CStr("E" & rst!EmployeeID)
           nod2.Expanded = True
       End With
       .MoveNext
   Loop
End With

End Sub

Private Sub PopulateTree2(EmployeeID As Long, NodKey As String)
'this will populate the training

Dim rst As New ADODB.Recordset

With rst
   .Open "SELECT [employee training].Employee_ID, [employee training]..
Trng_ID, [employee training].Taken, [employee training].Due, Training.Title "
& _
   "FROM [employee training] INNER JOIN Training ON [employee training].
Trng_ID = Training.Training_ID " & _
   "WHERE ((([employee training].Employee_ID)=" & EmployeeID & "));",
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
       Do Until .EOF
           With TrVw
               .Nodes.Add NodKey, tvwChild, "", rst!Title& "          " &
(Nz(rst!Taken, "-")) & "          " & (Nz(rst!Due, "-"))
               'no key need because there are no relationships below this
level to have a relation with
           End With
           .MoveNext
       Loop
   .Close
End With

End Sub

Code end ******************************

Thanks millions,
It works,

MyTreeView.Expanded = True

Thanks again,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

refresh treeview on a node 1
tree view list on drag 2
insert a node in to tree view 0
key in tree view list 2
tree view list node event 2
tree view list performance issue 1
delete tree view list 1
tree view list 3

Top