Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / ActiveX Controls / April 2004

Tip: Looking for answers? Try searching our database.

Tree view - how to edit, add or delete a node

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
chris - 16 Apr 2004 21:01 GMT
Hi,

I am using A2K with the tree view control 6 (SP4). I have succefully linked
2 tables and I can show all the appropriate data. How can I edit or delete a
node or even add a new one ? Is there a sample somewhere  ?

Thanks

Chris
Alex Dybenko - 17 Apr 2004 06:01 GMT
Try to look at this sample:
http://www.pointltd.com/Downloads/Details.asp?dlID=36

Signature

Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com

> Hi,
>
[quoted text clipped - 5 lines]
>
> Chris
chris - 18 Apr 2004 22:50 GMT
Thanks. This demo is very nice except that it doesn't show nor does it
explain how to dynamically add or delete nodes in the tree. From what I
understand I would have to rebuild the index -- how can it be done ?

Chris

> Try to look at this sample:
> http://www.pointltd.com/Downloads/Details.asp?dlID=36
[quoted text clipped - 15 lines]
> >
> > Chris
Paul Johnson - 19 Apr 2004 22:02 GMT
I copied this code out of my application that views "Folders" in treeview
control "xTree."
The key I am using is like "a 1", "a 2" etc, so you see why
(Recordset)!Parent is set to Mid(xTree.SelectedItem.Key, 3)

This code adds a new record to the Folders table, calls it "New Folder," and
adds a new child node to the selected node in the treeview control to
display it:
------------------------------------------------
Private Sub cmdNewFolder_Click()
On Error GoTo Err_cmdNewFolder_Click
   If xTree.SelectedItem Is Nothing Then Exit Sub

   With CurrentDb.OpenRecordset("Folders")
       .AddNew
       !Foldername = "New Folder"
       !Parent = Mid(xTree.SelectedItem.Key, 3)
       .Update
       .MoveLast
       xTree.Nodes.Add xTree.SelectedItem, tvwChild, "a " & !FolderID,
!Foldername
       xTree.SelectedItem.Expanded = True
   End With

Exit_cmdNewFolder_Click:
   Exit Sub

Err_cmdNewFolder_Click:
   MsgBox Err.Description
   Resume Exit_cmdNewFolder_Click

End Sub
------------------------------------------------
This sub removes a node, and deletes the corresponding record from the
Folder table:
------------------------------------------------
Private Sub cmdDeleteFolder_Click()

   If xTree.SelectedItem Is Nothing Or _
       DCount(1, "Reports", "[Parent]='" & xTree.SelectedItem.Key & "'") >
0 Or _
       xTree.SelectedItem.Children > 0 Then Exit Sub

   ' Delete the record from the table
   With CurrentDb.OpenRecordset("Folders", dbOpenDynaset)
       .FindFirst "FolderID=" & Mid(xTree.SelectedItem.Key, 3)
       .Delete
   End With
   xTree.Nodes.Remove xTree.SelectedItem.Index
End Sub
------------------------------------------------
Another example of an update you may want to perform.  My code assumes there
will be only one user in the database editing folder names, so I didn't work
in any error-trapping with the NoMatch method:
------------------------------------------------
Private Sub xTree_AfterLabelEdit(Cancel As Integer, newstring As String)
   With CurrentDb.OpenRecordset("folders", dbOpenDynaset)
       .FindFirst "[FolderID] = " & Mid(xTree.Object.SelectedItem.Key, 3) '
use NoMatch for multiple user environment
       .Edit
       .Fields!Foldername = newstring
       .Update
   End With
End Sub
------------------------------------------------
Maybe these will be of some help.

Paul Johnson

> Thanks. This demo is very nice except that it doesn't show nor does it
> explain how to dynamically add or delete nodes in the tree. From what I
[quoted text clipped - 22 lines]
> > >
> > > Chris
chris - 19 Apr 2004 22:25 GMT
Thanks a lot Paul, I'll try that. I'll post back the results.

> I copied this code out of my application that views "Folders" in treeview
> control "xTree."
[quoted text clipped - 92 lines]
> > > >
> > > > Chris
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.