Hierarchical Data, Recursion, Tree-View, and a another Great Custom Class (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
And it's still less than a mega in size
It is just code so it does a lot but code does not take up much room.
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
What you screen captured and the version uploaded aren't in synch. I had a version 7 2 day's ago. Maybe version 8 needs to be loaded?

I've attached 10 .bmp files that have been named to match the primary key (e.g. 1.BMP). I'm tracking there are 22 records in the t_E2E table. There has to be a way to handle not having a picture for every node.

In a query, how do you extract the "Get Level" value for each record that you are able to obtain with the button click? I wish it was as easy as SelectedNodeLevel([E2E_ID]), but that didn't work.

Update 7
Added Right click function
1) Command bar when off node
2) Command bar when over node
Duplicates a lot of the other functions

Do you have any icons you want? THey should be 32X32 pixel BMPs. With Drag and drop it will be very hard to modify the images per level of node. View attachment 79467
 

Attachments

  • bitmaps.zip
    17.5 KB · Views: 25

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
Try the download now. I must have zipped up the wrong file.
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
Right click on the tree is only giving me expand and collapse the tree. Is there a trick to showing the other options?
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
I see that it's all the way to the right when that function works. Is there a way to flip it so Expand tree is off the tree and the other functions are when you've made a specific node selection?
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
Edit node sees to always default back to the top record, regardless of the node you're on.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
All of this works fine for me, it is as if your Hit/Test (determining if over a node) is not working. For me if I am over a node it gives the full menu. If not over the node gives the expand and contract. When I edit a node it is the proper node. Something is wacky on your end. What if you close and comeback. But if it is not finding the selected node then this will not work.
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
Would monitor size or resolution have anything to do with it and/or having a modal form? I'll try again when I get back home.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
Screen resolution should not matter. Maybe the mouse could. Can you try a different mouse? Definitely doing the opposite of mine
In a query, how do you extract the "Get Level" value for each record that you are able to obtain with the button click? I wish it was as easy as SelectedNodeLevel([E2E_ID]), but that didn't work
You could write to the table on close, or you could calculate show it on the fly. Where and how do you want to display this. You could do it in a query, but the information would come from the tvw. I could be done, but you would need a function on the form. The query calls the function passing in the PK and gets the level back.

You have units of different Echelons and both operational and supporting establishment. Is that the interests in the levels or are these just random organizations. Do you want certain insignia at specific levels?
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
Ref the icons, it's just a proof of concept, not tied to a level but to a primary key.

Ref the get level, I'd like to see it calculate on the query run.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
I do not think logically tying an image to a PK would make sense. Instead I assumed these were taskings an added a field "ResponsibleUnit" (Command) to the table. Then I simply gave the tasks assignements. TRADCOC, FORSCOM, AFC, AMC. I named the bitmaps the same as the commands. So the code is simply this for loading the images
Code:
Public Sub LoadImages()
  Dim nd As Node
  For Each nd In TVW.Nodes
    nd.Image = DLookup("ResponsibleUnit", "t_E2e", "E2E_ID = " & TVW.getNodePK(nd))
  Next nd
End Sub

I do not know why I thought adding the images was hard. It is simply associating the imagelist with the treeview and then using the name of the image.

Commands.jpg
 

Attachments

  • MajP TreeviewDemo V9.zip
    174.5 KB · Views: 31

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
I do not think logically tying an image to a PK would make sense. Instead I assumed these were taskings an added a field "ResponsibleUnit" (Command) to the table. Then I simply gave the tasks assignements. TRADCOC, FORSCOM, AFC, AMC. I named the bitmaps the same as the commands. So the code is simply this for loading the images
Code:
Public Sub LoadImages()
  Dim nd As Node
  For Each nd In TVW.Nodes
    nd.Image = DLookup("ResponsibleUnit", "t_E2e", "E2E_ID = " & TVW.getNodePK(nd))
  Next nd
End Sub

I do not know why I thought adding the images was hard. It is simply associating the imagelist with the treeview and then using the name of the image.

View attachment 79486
Thank you again. Nice visual.
I've been using the PK since sometimes abbreviations change. Allows the link to stay live. But having your way shows another TTP.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
You can use a name of your choice "Manpower", "Training", "Facilities" etc. instead of command, unit, agency names. As long as you match the names with those of the images in the imagelist. My point was that if you only assign images to certain nodes and not others, the tree view will be ugly. Those without images will have a blank, and there is no way you could have a different image for every node.
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
@MajP still having the same issue with the mouse or no mouse (using touch pad) figuring out where the nodes are. Visually, it looks like it thinks the nodes are on the right and the open space is on the left. I've rebooted, changed out the mouse, used the trackpad, etc....

Visuals attached below (yellow arrow shows where the mouse cursor was on the right click). I can get the functionality of moving the node up/down, editing but it's a different experience that what you have on your screen.

Regardless, I think we're down to showing me how to pull out the level of each node in a query (within qryE2ESort).
Adding back in the search vba code I added.
I'd recommend anchoring the treeveiw (down and across), the subform (bottom left) and code buttons (top right), so you can pull on the edges of the form and see more of the treeview without using the scrollbar.
Then it's removing the extra tables, fields, queries and code so we have a clean demonstration product.
 

Attachments

  • Picture1.png
    Picture1.png
    560.8 KB · Views: 26
  • Picture2.png
    Picture2.png
    512.6 KB · Views: 28

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
That is definitely opposite of what I would expect to see. I asked someone else to take a look. It is like your computer does think the nodes are on the other side. As a workaround for this machine you could try swapping the code in the two procedures. Not sure if that would work, but might. Besides that there is nothing I can do.
Code:
Private Sub tvw_RightClickOffNode()
  createCommandBarPopUpNoNode Me, Me.TVW
End Sub

Private Sub tvw_RightClickOnNode(PK As Variant)
  Me.TVW.TreeView.Nodes("E2E" & PK).Selected = True
  createCommandBarPopUpNode Me, Me.TVW
End Sub

Is it ok to write the levels to the table, similar to Sort on the forms close? Doing it in a query can be done, but will be strange. You will have to build a public function in the E2E Form that returns the node level. Then the query would have a calculated control I have never in a query called a form to return a public class function value. Need to understand how you want to use it, because calculating on the fly can be done but it will be a simple but convoluted process. Also it would be the same as referencing control values on a form, you can only use the query when the treeview is open. It would be a query calling a procedure on a form, that references an object , that references another object, that references a collection,, and then loops the objects in that collection to return in a function back to the calling function a count. Make sense:unsure:
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
Flipping the vba code didn't work. I got a compile error on the PK portion of the below line. Variable not defined.

Code:
Private Sub tvw_RightClickOffNode()
  Me.TVW.TreeView.Nodes("E2E" & PK).Selected = True
  createCommandBarPopUpNode Me, Me.TVW
End Sub

Writing the values to a table is fine, I was hoping to reduce the amount of data I'm storing but based on how your describing the process pushing the values to the table is fine.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
actually that would not work
Try in the class changing
Code:
Private Sub mTVW_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
  Dim NodeHit As Node
  If Button = 2 Then
    Set NodeHit = mTVW.HitTest(x, y)
    If Not NodeHit Is Nothing Then
      RaiseEvent RightClickOnNode(Me.getNodePK(NodeHit))
    Else
      RaiseEvent RightClickOffNode
    End If
  End If
End Sub
To
Code:
Private Sub mTVW_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
  Dim NodeHit As Node
  If Button = 2 Then
    Set NodeHit = mTVW.HitTest(x, y)
    If Not NodeHit Is Nothing Then
      RaiseEvent RightClickOffNode
    Else
      RaiseEvent RightClickOnfNode(Me.getNodePK(NodeHit))
    End If
  End If
End Sub
I do not have much confidence.
 

dgreen

Member
Local time
Today, 02:49
Joined
Sep 30, 2018
Messages
396
Compile error on RaiseEvent RightClickOnfNode.
Is there additional code I'd need to run it?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
That is a typo. Remove the leftover "f". OnNode not OnfNode
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:49
Joined
May 21, 2018
Messages
4,015
I added the calculation and update of the levels. In the autolevel procedure I just added code to write the levels to the table. The procedure to get a level for a given node already existed in the class.
Code:
   strSql = "Update t_E2E SET Level_ID = '" & LevelID & "', [Level] = " & TVW.GetNodeLevel(TVW.getNode("E2E" & PK)) & " WHERE E2E_ID = " & CLng(PK)
 

Attachments

  • MajP TreeviewDemo V11.zip
    156.8 KB · Views: 32

Users who are viewing this thread

Top Bottom