I added the feature to move a node up and down in its level. These procedures are in the class module. I demo how you can update a node by updating the record in the subform.
I added the feature to move a node up and down in its level. These procedures are in the class module. I demo how you can update a node by updating the record in the subform.
Public Function ChildNodes(ByVal TheParentNode As node) As Collection
Dim intCounter As Integer
Set ChildNodes = New Collection
Dim TheNode As node
If Not TheParentNode.Child Is Nothing Then
Set TheNode = TheParentNode.Child
Else
Exit Function
End If
Do While Not TheNode Is Nothing
ChildNodes.Add TheNode
Set TheNode = TheNode.Next
Loop
End Function
For demo purposes I only demoed changes in the subform updating the changes on the node. I will demo using the node label change event to update the table. I can get you something later tonight.The update changes button isn't refreshing the values in the subform based on what's happened in the treeview.
Private Sub cmboNode_Change()
'https://stackoverflow.com/questions/48133260/display-records-in-access-db-combobox-on-any-text-typed-by-user
'test number of characters entered - if greater then 2 then assign rowsource
cmboNode.SetFocus
If Len(Me.cmboNode.Text) > 0 Then
'set the rowsource to match user search criteria
Me.cmboNode.RowSource = "SELECT qryE2E.E2E_ID, qryE2E.nodeText FROM qryE2E WHERE qryE2E.nodeText LIKE '*" & Me.cmboNode.Text & "*' ORDER BY qryE2E.nodeText"
'show the search in real-time
Me.cmboNode.Dropdown
Else
'set to no
Me.cmboNode.RowSource = "SELECT qryE2E.E2E_ID, qryE2E.nodeText FROM qryE2E ORDER BY qryE2E.nodeText"
End If
End Sub
Private Sub cmboNode_Click()
'http://www.utteraccess.com/forum/index.php?showtopic=2033577
'Clear combo box on click. Reduce time to clear values in order to search for a new record.
Me.cmboNode = Null
End Sub
Private Sub cmboNode_LostFocus()
Me.cmboNode.RowSource = "SELECT qryE2E.E2E_ID, qryE2E.nodeText FROM qryE2E ORDER BY qryE2E.nodeText"
End Sub
@dgreen
Update 5 Attached. It includes new features
1. Updating the table based on a change in the node label.
2. Auto generating your Levels.
3. Fixes to the move up move down
Still need to add a feature to add a new record, and do icons in the treeview. Any other things to demo? I have not put comments or organized the code so I hope you can follow.
The code to make the auto levels is in the button UpdateLevels. It seems to work well in IMO. I move everything around then update the levels. This is pretty complicated and could never be done in any form of SQL this is done by reading through the try, creating a dictionary, and then reading back through the dictionary. However if you want it to renumber every time you drag and drop then call it at that time or call it on close. The issue is it has to reload the tree and could be an annoyance.1) A column in a query that generates an autogenerated Level_ID (e.g. L.1.10.4)
Not sure what you are asking. When you close the sort order is saved so then it opens as last sorted. That is how the move up and down stay sorted.2) A column in a query that generates a sortable value that wen sorted A-Z matches the treeview.
No demo purposes can delete3) In qryOutput, is the Path field supposed to be populated?
If you want the levels you can populate on load and update when moved. I built a method for node level. You want levels in the table populated?4) Populate the Level column in t_E2E as changes to the treeview occur.
Would you consider using my attached version as your starting point for future improvements?
Sure it would be clearer. The other form only showed that you could union many to many and still make a tree.
The code to make the auto levels is in the button UpdateLevels. It seems to work well in IMO. I move everything around then update the levels. This is pretty complicated and could never be done in any form of SQL this is done by reading through the try, creating a dictionary, and then reading back through the dictionary. However if you want it to renumber every time you drag and drop then call it at that time or call it on close. The issue is it has to reload the tree and could be an annoyance.
Not sure what you are asking. When you close the sort order is saved so then it opens as last sorted. That is how the move up and down stay sorted.
No demo purposes can delete
If you want the levels you can populate on load and update when moved. I built a method for node level. You want levels in the table populated?
I pulled out the tables and queries that weren't related to the E2E table, just to visually simplify things for me.
I anchored the treeview and subform, so you can pull the modal form wider and the box gets larger, supporting when the tree has long branches.
I modified the qryE2E to include the E2E_ID (primary key). I leveraged this query to make the combo box more dynamic (mid string text search).
I put the below code on the cmboNode to make this search work
I will call it on form load as well. That way if you forget it will ensure it auto levels. But I would keep the button so you can move around a few things and then auto level. You could try it on the drag drop, but it may be annoying if the data gets large.#1 - if it updated on form closing or click the update button, that would be great.
That one you can see. Notice sorted in "tree" sort.#2 - I missed the fact you have it sorting 1-n, I had thought it was just the sort within the node.
Level_ID | Parent_ID | Sort |
---|---|---|
L1 | | 1 |
L1.1 | 106 | 2 |
L1.1.1 | 1 | 3 |
L1.2 | 106 | 4 |
L2 | | 5 |
L2.1 | 142 | 6 |
L3 | | 7 |
L4 | | 8 |
L4.1 | 288 | 9 |
L4.1.1 | 796 | 10 |
L4.1.1.1 | 104 | 11 |
L4.1.2 | 796 | 12 |
L4.1.2.1 | 289 | 13 |
L5 | | 14 |
L5.1 | 795 | 15 |
L5.1.1 | 140 | 16 |
L5.1.1.1 | 144 | 17 |
L5.1.1.1.1 | 146 | 18 |
L5.1.1.2 | 144 | 19 |
L5.1.2 | 140 | 20 |
L5.1.2.1 | 148 | 21 |
L5.2 | 795 | 22 |
L5.2.1 | 797 | 23 |
That is easy the code is basically there.#4 - yes please.
That code is in .net and not vba. I do not know if something like that exists in vba.So would this code not be able to provide that custom right click (e.g. shortcut menu)?