?
Solved

Treview - Move Data into an Active Treview Control

Posted on 2011-10-12
9
Medium Priority
?
172 Views
Last Modified: 2012-08-13
I want to take a tree view control on the left of a form and a data sheet on the right.  I would like to move data from the right form and put it under a specific heading on the tree view.  One value from the right could be under multiple headings on the tree.

So the perfect scenario would be for the user to highlight a value on the tree and highlight a value on the right form, push a button - and the value is still on the right but also under the heading on the Left.

Any help is greatly appreciated.
LJG

Note: The attached Treeview is Reader's Companion.mdb by Helen Feddema



   
TreeView-To-ExpEx2.jpg
0
Comment
Question by:LJG
  • 4
  • 4
9 Comments
 
LVL 35

Expert Comment

by:Norie
ID: 36959642
Is there meant to be a file attached or do you just mean the image?

0
 
LVL 2

Author Comment

by:LJG
ID: 36960239
Sorry - Just the image
0
 
LVL 85
ID: 36960830
Do you fully understand how the Treeview is populated? It's just a "tree view" of your related tables, and so all the Child Items of Greg Bear are included under  that "root" item, and so on.

So if you wish to move an item from the Greg Bear root to the Kage Baker root, you'd have to move that data IN THE TABLES and then repopulate the treeview - assuming, of course, that you want these changes to "stick" when you close down this form.

You can do that in several ways, but of course you'd have to have the info necessary to make those changes - for example, you'd need the PrimaryKey value for Kage Baker. Once you do this, you'd just run a simple UPDATE query, and then refresh your treeview.

If you're talking about something else, then please explain further.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 35

Expert Comment

by:Norie
ID: 36961304
You can add items, delete items, drag and drop items in a treeview but the changes you make won't be reflected in the source data.

So you would need to write the data back to the table either when the change is made or when you close the form.

0
 
LVL 2

Author Comment

by:LJG
ID: 36963376
Thanks for the info

>> My Basic Question:
 I want to do a simple add of "Merry Christmas..." under "Bisson, Terry" on the treeview without repopulating the treeview.


>> Assumed Facts of My Process:
    1) I have a table of "tbl_Customers" (Anderson, Atwood, Baker ....) (I know in Helen's example they are authors)
    2) I have a table that is connected to customers (tbl_Purchases) that contains all the books the customer bought.
    3) By working with tbl_Customers and tbl_Purchases, I fill in the treeview control on the form.  Hence I get that Stephen Booth bought "Black Dog: A...)

>>The Process I see
    1) The user clicks on "Bisson, Terry" in the treeview control and then clicks on "Merry Christmas..." on the right form and then clicks a button "Add"
    2) At that point I call a stored procedure that adds"Merry Christmas..." and "Bisson, Terry" to tbl_Purchases
    3) I want to do a simple add of "Merry Christmas..." under "Bisson, Terry" on the treeview without repopulating the treeview.  The treeview is not directly hooked to the tables so I'm  just am looking for a simple way to add it to the treeview.



         
 
0
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 36963674
It's pretty easy to add to the treeview.

This will add a child to the selected node.
Set selNode = tvwBooks.Object.SelectedItem
    
tvwBooks.Nodes.Add selNode, tvwChild, "Xmas",  "Merry Christmas"

Open in new window

Bad example I know but it kind of show's how it's done.

To update the tables you would need to add a new record to tblBooks.

Then using that ID and the author ID you need to add a record to tblBookAuthors.

You can get the author ID from the key of the author node.

After all that's done succesfully both table and treeview should be updated.

The next time the treeview is populated from the table it should reflect the change(s) made.

The whole code might look something like this.
  Dim selNode As Node
    Dim AllNodes As Nodes
    Dim NewBookID As Long
    Dim AutID As Long

    Set selNode = tvwBooks.Object.SelectedItem


    AutID = Val(Mid(selNode.Key, 9))

    tvwBooks.Nodes.Add selNode, tvwChild, "Xmas", "Merry Christmas"

    CurrentDb.Execute "INSERT INTO tblBooks(Title) VALUES('Merry Christmas')"


    NewBookID = DMax("BookID", "tblBooks")


    CurrentDb.Execute "INSERT INTO tblBookAuthors (AuthorID, BookID) VALUES (" & AutID & "," & NewBookID & ")"

Open in new window

0
 
LVL 2

Author Closing Comment

by:LJG
ID: 36965927
imnorie

Thanks so much for the answer.  You have the points, but if you have time could you give me an explanation of the following line.

tvwBooks.Nodes.Add selNode, tvwChild, "Xmas", "Merry Christmas"

>>> I undersstand
    tvwBooks = Treeview Name
    Nodes = Nodes are what we see in the tree and we want to add one
    Add = we want to add a node
     "Merry Christmas" = The Value I want to add

>>> I don't undersstand
     selNode = ??? Is this saying selected node???
     tvwChild = ??? Is this saying we are adding a child to the selected node???
      "Xmas" = ??????

Thanks again for all the help
LJG
0
 
LVL 35

Expert Comment

by:Norie
ID: 36965955
selNode is a variable that is a reference to the selected node in the treeview.

Using tvwChild is to add the new child node under the selected node.

'Xmas' is really just arbitrary - couldn't think of anything else to use at the time.

When I think about it using the ID of the new book would probably be a better option.

To do that the order would need to be changed a little, something like this

1 Add book to table using SQL.

2 Get new book's ID.

3 Add new node, with book's ID as the Key and the book title as Text.

The code is based on the example database so there's probably a lot of things that would need changing when
implementing something like this in your own database.
0
 
LVL 2

Author Comment

by:LJG
ID: 36965964
Thanks!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

862 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